4

I am using docker version 1.1.0, started by systemd using the command line /usr/bin/docker -d, and tried to:

  • run a container
  • stop the docker service
  • restart the docker service (either using systemd or manually, specifying --restart=true on the command line)
  • see if my container was still running

As I understand the docs, my container should be restarted. But it is not. Its public facing port doesn't respond, and docker ps doesn't show it.

docker ps -a shows my container with an empty status:

CONTAINER ID        IMAGE                   COMMAND                CREATED             STATUS                         PORTS                    NAMES
cb0d05b4e0d9        mildred/p2pweb:latest   node server-cli.js -   7 minutes ago                                      0.0.0.0:8888->8888/tcp   jovial_ritchie      
...

And when I try to docker restart cb0d05b4e0d9, I get an error:

Error response from daemon: Cannot restart container cb0d05b4e0d9: Unit docker-cb0d05b4e0d9be2aadd4276497e80f4ae56d96f8e2ab98ccdb26ef510e21d2cc.scope already exists.
2014/07/16 13:18:35 Error: failed to restart one or more containers

I can always recreate a container using the same base image using docker run ..., but how do I make sure that my running containers will be restarted if docker is restarted. Is there a solution that exists even in case the docker is not stopped properly (imagine I remove the power plug from the server).

Thank you

Mildred
  • 3,887
  • 4
  • 36
  • 44
  • It seems related to this issue: https://github.com/dotcloud/docker/issues/6675 – Mildred Jul 16 '14 at 15:06
  • 2
    Problably not related to the error, but `--restart=true` is not valid when looking at the [documentation](https://docs.docker.com/reference/run/#restart-policies-restart), what you are looking for is `--restart=always` – Guillaume Petit Oct 18 '15 at 15:39

1 Answers1

1

As mentioned in a comment, the container flag you're likely looking for is --restart=always, which will instruct Docker that unless you explicitly docker stop the container, Docker should start it back up any time either Docker dies or the container does.

tianon
  • 1,866
  • 3
  • 22
  • 37