kamal icon indicating copy to clipboard operation
kamal copied to clipboard

"docker: Conflicting options: --restart and --rm"

Open artemgordinskiy opened this issue 1 year ago • 2 comments

I get this error when I try to SSH into one of my application containers if its options include restart: unless-stopped.

Reproduction steps:

  1. Update a server configuration in deploy.yml to have the following option:
options:
  restart: unless-stopped
  1. Run kamal app exec bash -i (or any other exec command for that matter)
  2. Get the following error:
kamal app exec bash -i
Get most recent version available as an image...
Launching interactive command with version latest via SSH from new container on 192.168.1.5...
docker: Conflicting options: --restart and --rm.
See 'docker run --help'.

Kamal runs the command using docker run --rm while also including all the options from deploy.yml, which works unless one of your options is the one mentioned above.

I'm not saying this is a bug in Kamal, but I would like to hear if anyone has any ideas about fixing or getting around this issue :)

artemgordinskiy avatar Mar 31 '24 13:03 artemgordinskiy

I also just ran into this. A workaround is to pass the --reuse flag which will run the command in an existing container. This works:

kamal app exec bash -i --reuse

Agree it would be better to just remove the --restart argument somewhere here though.

Does that seem like a reasonable option?

czue avatar Apr 02 '24 15:04 czue

@artemgordinskiy - setting the restart policy to unless-stopped is redundant, because Kamal will do that anyway, so you could remove the option from your config.

With a custom restart option, Kamal just tags it on the end, so we have docker run foo ... --restart-policy unless-stopped --restart-policy <policy-from-options> .... Docker just seems to pick the last one so we get the desired behaviour by chance.

@czue's your suggestion makes sense for the bug reported here

So we should:

  1. Replace unless-stopped with the user supplied restart policy rather than append it
  2. Remove the policy for app exec commands
  3. Disallow a policy of always - this would have undesired behaviour of restarting previously deployed versions after a docker restart.

djmb avatar May 02 '24 14:05 djmb