Article directory
Preface
This article mainly introduces some commands related to containers in docker. It is a summary of the Kuangshen course . It serves as a manual to help bloggers and students who use docker find and recall.
The experimental environment of this article: xhell+centos+docker
1. docker container command
0. Preparation work
Since a container can only be generated after having an image, let's do some preparatory work first: download a centos image (Ps: students who don't know how to download can first read the blogger's article about the basic commands of the image ).
1. Create a new container and start it
docker run [可选参数] image
Options introduction:
--name="Name" #给容器起名字用来区分容器
-d #后台方式运行
-it #使用交互方式运行,进入容器查看参数
-p # 指定容器的端口
2. Exit the container
exit #直接停止容器运行并退出
Ctrl + p + q# 容器不停止退出
3. List all running containers
docker ps #列出正在运行的容器
docker ps -a# 列出当前正在运行的容器和历史运行过的容器
docker ps -q#只列出容器ID
-n=? #只列出最近创建的多个个容器
4. Delete the container
docker rm 容器ID
docker rm -f $(docker ps -aq)#删除所有的容器
5. Start and stop container operations
docker start #启动容器
docker restart #重启容器
docker stop 容器id #停止容器运行
docker kill 容器id #强制停止容器的运行
Summarize
The above is the main content of this article, I hope it can be helpful to you.