Challenge, Medium,  on  Containers

Make a Container Restart Automatically After Podman Host Reboot

In this challenge, you'll make a containerized web application resilient to host reboots on a Podman-based system.

A web server is already running as a rootful (system-level) background container named app-1 and serves HTTP traffic on port 8080. You can verify it's working:

curl http://localhost:8080/

Since the container was started as root, you'll need to use sudo podman to manage it:

sudo podman ps

Your task is to configure the system and the app-1 container so that it automatically restarts whenever the machine reboots.

Hint: Enabling the Podman restart service

The podman-restart.service is a oneshot systemd unit that runs podman start for all containers with a restart policy of always at boot. You can see what it does exactly by running:

systemctl cat podman-restart.service

Check if it's enabled, and if not, enable it like any other systemd service.

If the app-1 container was started without a restart policy, update it so that Podman knows to restart it on boot.

Hint: Setting container restart policies in Podman

You can change the restart policy of an existing container without recreating it using:

sudo podman update --restart=<policy> <container>

Valid restart policies are: no, on-failure, always, and unless-stopped.

Once the restart service is enabled and the container's restart policy is set, reboot the machine:

sudo reboot

Now let's check if the app-1 container survived the reboot and came back online automatically with the same container ID: