Use to create a container of Docker's, Docker removed using the mirrored pull, query, delete

Suppose we now have the following image

1: Start with a simple container

docker container run // used to start a container

-it // container is interactive, and connected to the terminal

Command: docker container run --name percy -it ubuntu: latest / bin / bash // start a container, named percy

2: Exit container and keep the container operation

 

Run the terminal command ps -elf can view the processes running in the container, the first process is to run the Bash Shell, the second process is a temporary process, generated by ps -elf, command executing the process will end.

Press Ctrl-PQ: key combination will exit the container, but the container will not stop running.

Note: If you enter exit at the Bash Shell Bash Shell exits, this time due to the container without any process running, the container itself will be killed.

3: Check the container list

 

4: Life cycle of container

Execute the following command, and then press Ctrl-PQ exit container

 Use docker container stop percy stop the container

 Restart the container and try to bash even

 NOTE: Before deleting a container, the container will not lose the data. If the container is stored in the volume, even if the container is removed, the data will be saved.

5: stop the container

Container running docker container rm <container> -f // Destruction

6: Restart container policy

always: unless the container is explicitly stopped, such as by docker container stop command, otherwise the container will always try to restart a stopped state.

docker container run --name neve --restart always -it ubuntu:latest /bin/bash

You can see the container created before 23s, launched in 7s ago

 There unless-stopped and restarted on-failure policy, which is not presented here.

7: Remove container

快速清理所有容器可以用:docker container rm $(docker container ls -aq) -f                              //-f:表示强制执行清理命令

 

参考书目《深入浅出Docker》

上一篇:使用Docker之镜像的拉取、查询、删除

 

Guess you like

Origin www.cnblogs.com/wzt2019l/p/11323793.html