Consider:
docker run -it centos /bin/bash
I pressed Ctrl+D to exit it.
I want to continue to run this container, but I found I can't.
The only method is
docker commit `docker ps -q -l` my_image
docker run -it my_image /bin/bash
Am I right? Is there a better method? (I'm using docker 0.8.0.)
Use:
This will start all containers which are in the exited state.
This will connect to the particular container.
Explanation:
docker start
start a container (requires name or ID)-a
attach to container-i
interactive modedocker ps
List containers-q
list only container IDs-l
list only last created containerFollow these steps:
Run below command to see that all the container services both running and stopped on. Option
-a
is given to see that the container stops as wellThen start the docker container either by
container_id
or container tag namesSay from the above picture, container id 4b161b302337
So command to be run is
One can verify whether the container is running with
You can restart an existing container after it exited and your changes are still there.
If you want to continue exactly one Docker container with a known name:
If you want to do it in multiple, easy-to-remember commands:
docker ps -a
docker start -i <name/id>
The
-i
flag tells docker to attach to the container's stdin.If the container wasn't started with an interactive shell to connect to, you need to do this to run a shell:
The
/bin/sh
is the shell usually available with alpine-based images.