Docker basic operation commands
- One, docker mirror operation
- Two, container operation
-
- 1. Query the container
- 2. Create a container
- 3. Start the container
- 4. Start the container (one-time execution)
- 5. Stop the container
- 6. Continue to run in the background
- 7. Enter the container
- 8. Container export
- 9. Container import (image generation)
- 10. Delete the container
- 11. Batch delete containers
- 12. Batch delete containers in "exit" status
One, docker mirror operation
1. Query docker version
docker version && docker info
2. Search mirror
docker search nginx
dockersearch centos:7
PS: Linux distribution: alpine centos redhat Debian (apt package management, centos is rpm) production environment may be used
3. Download the mirror
docker pull镜像名称,例如:docker pull nginx
4. View the mirror list
docker images——查看当前docker下的下载镜像信息
5. Obtain mirror information
docker inspect 镜像ID
6. Add a mirror tag
docker tag nginx:latest nginx:Inmp
7. Delete
docker rmi 镜像名称
docker rmi 镜像标签
8. Mirror export
docker save -o文件名 镜像名
示例:
docker save -o nginx nginx:latest
9. Mirror import
docker load < nginx
使用场景:有的生产环境,企业不直接使用docker私有仓库,而是存放在一个ftp服务器中,按需上传下载
Two, container operation
1. Query the container
docker ps -a
2. Create a container
docker create -it nginx:latest /bin/bash
-i让容器的标准输入保持打开
t分配一个伪终端
3. Start the container
docker start 容器id
4. Start the container (one-time execution)
docker run centos:7 /usr/bin/bash -c ls /
5. Stop the container
docker stop 容器ID
6. Continue to run in the background
docker run -d centos:7 /bin/bash -c "while true;do echo hello;done"
7. Enter the container
1.使用run
docker run -it nginx:latest /bin/bash
2.exec(容器必须为开启状态)
docker exec -it 容器ID /bin/bash
8. Container export
docker export容器ID > 文件名
示例:
docker export容器ID > nginx_a
9. Container import (image generation)
docker import nginx_a nginx:latest
cat nginx_a | docker import --nginx:latest
10. Delete the container
docker rm 容器ID
11. Batch delete containers
docker ps -a | awk '{print "docker rm "$1"}' | bash
12. Batch delete containers in "exit" status
for i in `docker ps -a / grep -i exit | awk '{print $1}'`; do docker rm -f $i;done