Mildred
Mildred

Reputation: 3927

How to restart a container on docker restart (--restart=true doesn't work)?

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

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

Upvotes: 3

Views: 4396

Answers (1)

tianon
tianon

Reputation: 1904

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.

Upvotes: 1

Related Questions