podman-compose
podman-compose copied to clipboard
Restart Policy not set
when I use podman-compose to up my pods, restart policy is not set, while in docker-compose it sets restart policy. Output of docker inspect (Up by docker-compose) "RestartPolicy": { "Name": "always", "MaximumRetryCount": 0 }, while there is no key RestartPolicy when up by podman-compose in podman inspect
Ok. I'll try to do that this week end
@muayyad-alsadi Any news?)
@DesSolo Podman do not have any restart policy. you have to write a systemd script for it.
Not true, Podman has included restart policies for some time (I think we added it in the 1.4.x releases?)
@mheon I don't know exactly if restart policy is here in 1.4.x release. I'll check it and post here. But currently I am using "podman generate systemd" to specify restart policy.
@muayyad-alsadi You need any help with that? Would this be a good issue to start getting involved with podman-compose?
Any updates on this? Is this still worked on?
Does "restart: always" work well with podman-compose now?
Does "restart: always" work well with podman-compose now?
Any update?
this seems to be fixed here, but it's podman not respecting as @bilal-ameer-ivolve mensioned
https://github.com/containers/podman-compose/commit/047820dbf198bf27cd24f372afcc25c9395b5f44
Any news on this? Would be great :)
For the record I ran into this issue too. After switching from v0.1.5 to devel@HEAD the restart policy works as intended.
Do you have any plan to release another v0.x version?
Running podman-compose version 1.0.3 from pypi I still have this issue. in a docker-compose.yml file, the flag restart: unless-stopped
doesn't cause the container to start after a reboot, and neither does restart: always
@EzeKoren here is a buysbox docker-compose
and the output podman-compose up -d
services:
web:
image: busybox
command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8000"]
restart: always
podman run ... --restart always ... busybox /bin/busybox httpd -f -h /var/www/html -p 8000
as you can see it's passed
would you please share the output from your side (do down and up)
@muayyad-alsadi thank you for your reply. The container passed and it's executed normally after running podman-composed up
. After a reboot, the containers still exist but they're not started automatically as instructed by the flag, sorry if the previous comment was not clear.
I did manage to work around this issue by creating a systemd service using podman generate systemd --name container-name --files --new
(NOTE: this command must be run as sudo if it references a container in rootful mode), and then enabling and restarting said service.
It could be useful to either implement this functionality on podman-compose itself or at least document this workaround
this is quoted from podman manual page
--restart=policy
Restart policy to follow when containers exit. Restart policy will not take effect if a container is stopped via the podman kill or podman stop commands.
Valid policy values are:
• no : Do not restart containers on exit
• on-failure[:max_retries] : Restart containers when they exit with a non-zero exit code, retrying indefinitely or until the optional max_retries count is hit
• always : Restart containers when they exit, regardless of status, retrying indefinitely
• unless-stopped : Identical to always
Please note that restart will not restart containers after a system reboot. If this functionality is required in your environment, you can invoke Podman from a systemd.unit(5) file, or create an init script for whichever
init system is in use. To generate systemd unit files, please see podman generate systemd.
It could be useful to either implement this functionality on podman-compose itself or at least document this workaround
I'm working on integrating podman-compose
with systemd
there are some discussion about this.
I'm currently considering a unit with something like
ExecStartPre=/bin/podman-compose up --no-start
ExecStartPre=/bin/podman pod start pod_mypod
ExecStart=/bin/podman pod wait cnt1 cnt2 ...
I'm relatively new to containers, Linux, etc. But from what I can see, podman-compose
creates a pod for all the containers in the .yaml file and adds them to that pod. You can get the pod ID from podman pod ps
then use podman generate systemd --new
on the pod ID to generate a systemd definition for that pod that will behave like compose does, destroying and taking down the pod and it's containers whenever stopped. The problem is, that definition includes a full podman run
line for the containers in the compose file, and won't change whenever the YAML file is changed.
A solution I can think of would be for podman-compose to detect a restart: policy
in the services part of a compose file, and when needed create/enable a systemd serivce for the pod and relevant apps in the correct place (~/.config/systemd/user/
for rootless containers, /etc/systemd/system/
for rootful ones) to persist through a system reboot, and then delete that service file on podman-compose down
. However, persistance for rootless containers will also require user session lingering to be enabled to start the pod and containers on reboot and accomplish what Docker does with the daemon. Ideally the user would learn how to enable lingering if necessary when trying to run something rootless with a restart policy such as always
or unless-stopped
.
We definetly need a podman-compose generate systemd
just as we have podman generate systemd
or a compliance of the restart: always/unless-stoped
in this scenario!
Podman-compose seems to respect the restart policy, but the podman doesn't - I needed to enable the service that is not enabled by default:
systemctl --user enable podman-restart
https://github.com/containers/podman/issues/10539
I have a simpler solution, just use sudo apt install docker-compose
, it will install docker and docker-compose all togather.
So, there has no need to install other stuff.
Just for reference, this appears to be working fine for me, running: podman-compose version 1.0.6 podman version 4.5.1 on Fedora 38
@stephenpmurray I cannot this fully.
$ podman-compose -v
podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.4.1
podman-compose version 1.0.6
podman --version
podman version 4.4.1
exit code: 0
Works
services:
app:
restart: on-failure
Passed down to the podman create
call as --restart on-failure
.
Doesn't Work
services:
app:
deploy:
restart_policy:
condition: on-failure
Not passed down to the podman create
call.
@Jack12816 Sorry it looks like I misunderstood what was being discussed in the thread. Yes,
services:
app:
restart: ...
was working for me
Apologies for any confusion
I suggest closing this. On Debian 12.1 with
~ $ podman-compose version
['podman', '--version', '']
using podman version: 4.3.1
podman-composer version 1.0.3
podman --version
podman version 4.3.1
exit code: 0
containers with "restart: always" in docker-compose.yml will be restarted on reboot through
$ systemctl status podman-restart.service
● podman-restart.service - Podman Start All Containers With Restart Policy Set To Always
Loaded: loaded (/lib/systemd/system/podman-restart.service; enabled; preset: enabled)
Active: active (exited) since Sat 2023-09-09 14:10:11 CEST; 6min ago
Docs: man:podman-start(1)
Process: 1623 ExecStart=/usr/bin/podman $LOGGING start --all --filter restart-policy=always (code=exited, status=0/SUCCESS)
Main PID: 1623 (code=exited, status=0/SUCCESS)
Tasks: 10 (limit: 76833)
Memory: 18.4M
CPU: 1.630s
CGroup: /system.slice/podman-restart.service