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
?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With