Table of contents
1.4. Set docker to start automatically
1.6. View the running status of docker (green display means normal startup)
3.2. Search mirror images separately
Four, docker container command
4.2. View all containers (including running and stopped)
4.4. Access container Here 0862b7c9bb2f is the container ID
4.5, delete the container First to stop the running container
1. Basic commands of docker
1.1, start docker
systemctl start docker
1.2, close the docker
systemctl stop docker
1.3, restart docker
systemctl restart docker
1.4. Set docker to start automatically
systemctl enable docker
1.5. View docker version
docker version
1.6. View the running status of docker (green display means normal startup)
systemctl status docker
Two, docker help command
docker --help
For example, when we start the image, we forget to use the command
docker run --help
Three, docker image command
3.1. View the docker image
docker images
3.2. Search mirror images separately
docker images 镜像名
3.3. Pull the image without tag (version number) to pull the latest version latest version of the image in the docker warehouse. Add :tag to pull the specified version
docker pull 镜像名
docker pull 镜像名:tag
3.4, delete the image
#删除一个
docker rmi -f 镜像名/镜像ID
#删除多个 其镜像ID或镜像用用空格隔开即可
docker rmi -f 镜像名/镜像ID 镜像名/镜像ID 镜像名/镜像ID
#删除全部镜像 -a 意思为显示全部, -q 意思为只显示ID
docker rmi -f $(docker images -aq)
3.5. Forced deletion
docker image rm 镜像名称/镜像ID
Four, docker container command
4.1. View running containers
docker ps
4.2. View all containers (including running and stopped)
docker ps -a
4.3, run a container
# -it 表示 与容器进行交互式启动 -d 表示可后台运行容器(守护式运行) --name 给要运行的容器起的名字 /bin/bash 交互路径
docker run -it -d --name 要取的别名 镜像名:Tag /bin/bash
4.4. Access container Here 0862b7c9bb2f is the container ID
docker exec -it 0862b7c9bb2f /bin/bash
docker exec -it 容器id bashshell #进入当前正在运行的容器(开启一个新的终端)
docker attach 容器id #进入当前正在运行的容器(直接进入正在运行的终端)
4.5, delete the container First to stop the running container
docker stop 容器名/容器ID
Then the same as the delete instruction above
Container port to server port mapping
-p 宿主机端口:容器端口
For example
docker run -it -d --name mysql -p 8888:6379 mysql:5.7 /bin/bash
into the container
docker exec -it 容器ID /bin/bash
4.6. Exit the container
exit #容器停止退出
ctrl +P +Q #容器不停止退出
4.7. Container Management
docker start 容器id #启动容器
docker restart 容器id #重启容器
docker stop 容器id #停止当前正在运行的容器
docker kill 容器id #强制停止当前容器