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.)
You can restart an existing container after it exited and your changes are still there.
docker start `docker ps -q -l` # restart it in the background
docker attach `docker ps -q -l` # reattach the terminal & stdin
docker start -a -i `docker ps -q -l`
Explanation:
docker start
start a container (requires name or ID)
-a
attach to container
-i
interactive mode
docker ps
List containers
-q
list only container IDs
-l
list only last created container
Use:
docker start $(docker ps -a -q --filter "status=exited")
This will start all containers which are in the exited state.
docker exec -it <container-id> /bin/bash
This will connect to the particular container.
If you want to do it in multiple, easy-to-remember commands:
- list stopped containers:
docker ps -a
- copy the name or the container id of the container you want to attach to, and start the container with:
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:
docker start <name/id>
docker exec -it <name/id> /bin/sh
The /bin/sh
is the shell usually available with alpine-based images.
If you want to continue exactly one Docker container with a known name:
docker start `docker ps -a -q --filter "name=elas"`
If you have a named container then it can be started by running
docker container start container_name
where container_name is name of the container that must be given at the time of creating container. You can replace container_name
with the container id in case the container is not named. The container ID can be found by running:
docker ps -a
These commands will work for any container (not only last exited ones).
This way will work even after your system has rebooted.
To do so, these commands will use "container id".
Steps:
List all dockers by using this command and note the container id of the container you want to restart:
docker ps -a
Start your container using container id:
docker start <container_id>
Attache and run your container:
docker attach <container_id>
NOTE: I had tried this with linux system
Hope this helps someone!
docker start `docker ps -a | awk '{print $1}'`
This will start up all the containers that are in the 'Exited' state