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
?
First,
$ docker ps -a
shows all containers (the ones that are running and the stopped ones), so that is the reason you are not seeing your stopped container listed.Second, you can easily start a stopped container running:
Once the container has been started, you can run your command by:
The stuff you create in your container will remain inside your container as long as it exists. If you want to keep data even if your container is removed you can use a volume.
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.