How to continue a Docker container which has exite

2020-01-27 09:00发布

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.)

标签: docker
9条回答
地球回转人心会变
2楼-- · 2020-01-27 09:47

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
查看更多
Melony?
3楼-- · 2020-01-27 09:47
docker start `docker ps -a | awk '{print $1}'`

This will start up all the containers that are in the 'Exited' state

查看更多
地球回转人心会变
4楼-- · 2020-01-27 09:53

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:

  1. List all dockers by using this command and note the container id of the container you want to restart: docker ps -a

  2. Start your container using container id: docker start <container_id>

  3. Attache and run your container: docker attach <container_id>

NOTE: I had tried this with linux system

Hope this helps someone!

查看更多
登录 后发表回答