podman-compose icon indicating copy to clipboard operation
podman-compose copied to clipboard

Restart Policy not set

Open bilalbinameer opened this issue 4 years ago • 25 comments

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

bilalbinameer avatar Nov 25 '19 12:11 bilalbinameer

Ok. I'll try to do that this week end

muayyad-alsadi avatar Nov 25 '19 14:11 muayyad-alsadi

@muayyad-alsadi Any news?)

DesSolo avatar Jan 29 '20 17:01 DesSolo

@DesSolo Podman do not have any restart policy. you have to write a systemd script for it.

bilal-ameer-ivolve avatar Jan 30 '20 04:01 bilal-ameer-ivolve

Not true, Podman has included restart policies for some time (I think we added it in the 1.4.x releases?)

mheon avatar Jan 30 '20 04:01 mheon

@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.

bilal-ameer-ivolve avatar Jan 30 '20 05:01 bilal-ameer-ivolve

@muayyad-alsadi You need any help with that? Would this be a good issue to start getting involved with podman-compose?

kiview avatar Mar 04 '20 06:03 kiview

Any updates on this? Is this still worked on?

tooxo avatar Mar 28 '20 15:03 tooxo

Does "restart: always" work well with podman-compose now?

zx1986 avatar Jul 22 '20 03:07 zx1986

Does "restart: always" work well with podman-compose now?

Any update?

xamadev avatar Oct 19 '20 10:10 xamadev

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

muayyad-alsadi avatar Oct 19 '20 12:10 muayyad-alsadi

Any news on this? Would be great :)

paulkitt avatar Feb 15 '21 13:02 paulkitt

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?

rjuju avatar Nov 11 '21 09:11 rjuju

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 avatar Mar 02 '22 16:03 EzeKoren

@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 avatar Mar 03 '22 15:03 muayyad-alsadi

@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

EzeKoren avatar Mar 03 '22 15:03 EzeKoren

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 ...

muayyad-alsadi avatar Mar 03 '22 15:03 muayyad-alsadi

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.

WittyNameHere avatar Jul 19 '22 23:07 WittyNameHere

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!

Alwaysin avatar Nov 16 '22 13:11 Alwaysin

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

interj avatar Feb 07 '23 16:02 interj

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.

yingshaoxo avatar May 09 '23 06:05 yingshaoxo

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 avatar Jun 29 '23 10:06 stephenpmurray

@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 avatar Jun 30 '23 11:06 Jack12816

@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

stephenpmurray avatar Jul 03 '23 08:07 stephenpmurray

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

meyca avatar Sep 09 '23 12:09 meyca