Let's explore how you can automatically start containers while booting.
To automatically start containers in a standalone situation, you can create systemd-unit files
for rootless containers and manage them with systemctl.
That's what we have just seen, and you have seen how easy that is to do with quadlets.
If Kubernetes or OpenShift is used, containers will be automatically started by default.
Because the .service files that are generated for the quadlet.container files are generated,
you cannot enable them in the way that the regular service is enabled.
And to compensate for this, the install section with the directive like wanted by is default.target
needs to be added to the .container file.
And as a result, when the system boots and the user logs in, the automatically generated
service file is started automatically.
Now you need to know a little bit about linger.
What is that?
Well, this is about the fact that user units are normally only started when the user logs in.
Use loginctl enable linger, and that will start the service manager for a specific user
without the need for the user to log in.
And after generating .service files to start containers as described before, this will
allow these services to start when the system starts.
So how would that work?
Well, first you use sudo loginctl enable linger on the user.
Then you can verify using loginctl show user.
And if you want to disable, sudo loginctl disable linger will get rid of the feature.
Let me show you how to use all of this to create a quadlet container that will automatically
start while your system is rebooting.
So first, I'm creating a user, Linda, might already exist.
And next, I can use sudo loginctl enable linger, Linda.
And next, ssh linda at localhost.
Now why do I ssh?
Well, that is because it doesn't work from an su-minus subshell.
So you really need to be in the login shell.
Now for you, so Linda, I'm creating the required directory structure.
So mkdir minus p on .config slash containers slash systemd.
And I'm changing into that directory.
And then while I'm in that directory, I can create a container file.
So mynginx.container.
And there I put my unit with the descriptions, not really functional.
Most importantly, I'm entering the container section where we set the image to the image
that I want to use, docker.io slash library slash nginx colon latest.
And I use an install section.
And this install section is wanted by this default.target.
And now I'm using systemctl minus minus user status on mynginx.service.
And we can see that the service has been generated.
And that is all that we need for now.
So now I'm going to exit.
And I'm going to sudo reboot.
Because the mission here is to show you that the container is automatically coming up after a reboot.
Right, now that I'm back on my system after the reboot, let me use psfaux.
Pipe that through less.
And look for processes that are started by user Linda.
And there we can see that there is the conmon.
This process with all of its arguments is how a container is started.
If you look at it from the container host perspective.
And there you can see nginx.
This is the nginx container that has been started by using the user Linda quadlet.