How to Autostart Podman Containers on Windows ?
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:
- Open a command prompt and log in to the Podman machine using the
podman machine ssh
command. - Locate and open the
/usr/lib/systemd/system/podman.service
file using a text editor (such as vim). - Add the following line to the
[Service]
section, after theExecStart
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.