How to Autostart Podman Containers on Windows ?

2 min readJun 7, 2023

These days we can run containers everywhere, you can run them in every platform even on Microsoft Windows :))

With the installation of “Podman Desktop,” you can enable the “Engine autostart” and “Login start” options in settings to ensure automatic startup.

If you run container with following command:

podman run -d --restart always --name my-test-container nginx:latest

Problem:

We expect to see this container runs after the ٌWindows OS reboot, but it does not.

This problem is similar to an issue reported on the Podman repository, while the solutions provided in the issue discussions are primarily for Linux and we run Podman on windows!. Really !?

No it dose not , noting that Podman on Windows runs within the Windows Subsystem for Linux (WSL).

Solution:

To address this problem, we need to implement one of the solutions within the Podman machine running on Windows. Follow these steps:

  1. Open a command prompt and log in to the Podman machine using the podman machine ssh command.
  2. Locate and open the /usr/lib/systemd/system/podman.service file using a text editor (such as vim).
  3. Add the following line to the [Service] section, after the ExecStart line:
ExecStartPost=/bin/bash -c 'podman start --filter restart-policy=always --all'

Ensure that your file appears similar to the following:

[Unit]
Description=Podman API Service
Requires=podman.socket
After=podman.socket
Documentation=man:podman-system-service(1)
StartLimitIntervalSec=0

[Service]
Delegate=true
Type=exec
KillMode=process
Environment=LOGGING="--log-level=info"
ExecStart=/usr/bin/podman $LOGGING system service
ExecStartPost=/bin/bash -c 'podman start --filter restart-policy=always --all'

[Install]
WantedBy=default.target

As we have made changes to the service file, we need to notify systemd about this modification. To reload systemd, run the following command:

systemctl daemon-reload

Conclusion:

By following these steps, you have successfully configured Podman on Windows to autostart containers with the --restart always option. Now, whenever your Windows system reboots, the containers will automatically start.

--

--

Payam Saderi
Payam Saderi

Written by Payam Saderi

Now I am a DevOps engineer! I started to work as a front-end developer in 2000, aslo I have more than 16 years of experiences as a Linux system administrator

Responses (3)