Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How restart a stopped docker container

Tags:

docker

I launch a docker container from an image with the following command:

$ docker run -d myimage /bin/bash -c "mycommand" 

When "mycommand" is finished, the container is stopped (I suppose it is stopped), but it is not deleted, because I can see it with this command:

$ docker ps -a 

Is there any way to restart this container with the same parameters and keep data generated by mycommand?

like image 368
Bob5421 Avatar asked Sep 23 '16 18:09

Bob5421


People also ask

Can we restart a stopped container docker?

Use a restart policy Restart the container if it exits due to an error, which manifests as a non-zero exit code. Optionally, limit the number of times the Docker daemon attempts to restart the container using the :max-retries option.

How do I restart a docker container on failure?

always – Docker will ensure the container is always running. If the container stops, it will be immediately restarted. You can still manually stop the container with docker stop but Docker will bring it back up next time the daemon restarts. on-failure – The container will get restarted if it stops because of an error.


1 Answers

Yes, when the initial command finish its execution then the container stops.

You can start a stopped container using:

docker start container_name

If you want to see the output of your command then you should add -ai options:

docker start -ai container_name

PS. there is a docker restart container_name but that is used to restart a running container - I believe that is not your case.

like image 159
lmtx Avatar answered Nov 07 '22 14:11

lmtx