2. Docker common command set (simple and detailed)

1. Help command

The address of the official help document: https://docs.docker.com/engine/reference/commandline/docker/

docker version       #显示docker的版本信息
docker -v            #显示docker的简单版本信息
docker info          #显示docker的系统信息,包裹镜像和容器的数量
docker 命令 --help   #帮助命令

2. Mirroring command

    • docker images view image
[root@NS ~]# docker images  #查看本机所有镜像
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   15 months ago   13.3kB

# 解释
REPOSITORY  #镜像的仓库源
TAG         #镜像的标签
IMAGE ID    #镜像的ID
CREATED     #镜像的创建时间
SIZE        #镜像的大小

#可选项
-a --all    #列出所有镜像
-q --quiet  #只显示镜像的ID
    • docker rmi delete image
docker rmi -f 容器id                  #删除指定的镜像
docker rmi -f 容器id 容器id 容器id     #删除指定的多个镜像
docker rmi -f $(docker images -ap)    #删除全部镜像  递归删除
$(docker images -ap)                  # 查询出所有镜像id
3. docker search search image
[root@NS ~]# docker search mysql
NAME                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                           MySQL is a widely used, open-source relation…   13671    [OK]
mariadb                         MariaDB Server is a high performing open sou…   5224     [OK]
phpmyadmin                      phpMyAdmin - A web interface for MySQL and M…   718      [OK]
percona                         Percona Server is a fork of the MySQL relati…   598      [OK]
bitnami/mysql                   Bitnami MySQL Docker Image                      80       [OK]

#可选项 通过搜索来过滤
-f=STARS=3000  #搜出出来的镜像就是STARS大于3000的
[root@NS ~]# docker search mysql -f=STARS=3000
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql     MySQL is a widely used, open-source relation…   13671     [OK]
mariadb   MariaDB Server is a high performing open sou…   5224      [OK]
4. docker pull download image
docker pull 镜像名[:tag]

[root@NS ~]# docker pull mysql
Using default tag: latest          #如果不写 tag版本,默认就是 latest 最新版本
latest: Pulling from library/mysql
72a69066d2fe: Pull complete        #分层下载,docker images的核心 联合文件系统
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
688ba7d5c01a: Pull complete
00e060b6d11d: Pull complete
1c04857f594f: Pull complete
4d7cfa90e6ea: Pull complete
e0431212d27d: Pull complete
Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709 # 签名
Status: Downloaded newer image for mysql:latest  
docker.io/library/mysql:latest     #真实地址

#两个命令相同
docker pull mysql
docker pull docker.io/library/mysql:latest

#指定版本下载
docker pull 镜像名[:tag]
docker pull mysql:5.7   #下载真实的镜像版本

[root@NS ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
72a69066d2fe: Already exists   #共用本机已下载mysql的镜像联合文件
93619dbc5b36: Already exists
99da31dd6142: Already exists
626033c43d70: Already exists
37d5d7efb64e: Already exists
ac563158d721: Already exists
d2ba16033dad: Already exists
0ceb82207cd7: Pull complete    #这里是下载的文件
37f2405cae96: Pull complete
e2482e017e53: Pull complete
70deed891d42: Pull complete
Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

3. Container command

Explanation: We can create a container only when we have a mirror, and download a centos mirror to test and learn

docker pull centos
    • Create container and start
1.1 docker run [optional parameter] mirror image
#docker run 的可选参数说明
--name 容器名字  #容器名字 cengos1 cengos2 用来区分容器
  -a            #连接到STDIN、STDOUT或STDERR
  -c            #CPU份额(相对权重)
  -d            #在后台运行容器并打印容器ID
  -e            #设置环境变量
  -h            #容器主机名
  -i            #交互式保持STDIN打开,即使未连接
  -l            #在容器上设置元数据
  -m            #内存限制
  -P            # 大p 随机指定端口
  -p            # 小p 指定容器的端口
  -t            #分配伪tty
  -u            #用户名或UID
  -v            #绑定装载卷
  -w            #容器内的工作目录
1.2 docker run common commands
--name 容器名字  #容器名字 cengos1 cengos2 用来区分容器
-d             #后台方式运行
-it            #使用交互方式运行,进入容器内
-p             #小p 指定容器的端口 8080:8080
   -p 主机端口:容器端口     (常用方式)
   -p ip:主机端口:容器端口
   -p 容器端口  不往外映射
    容器端口   不往外映射

-P             #大P 随机指定端口
1.3 docker run run test command
docker run -it centos:7 /bin/bash  #启动容器
exit                               #退出容器到主机
2. List all running containers
docker ps          #列出正在运行的容器
docker ps -a       #列出所有运行过的容器
docker ps -a -n=1  #列出最近1次运行的容器
docker ps -aq      #列出所有运行过的容器id
3 Exit the container
exit #直接容器停止并退出
Ctrl + P + Q  #容器不停止并退出
4 Delete the container
docker rm -f 容器id                #删除容器
docker rm -f $(docker ps -aq)      #删除所有容器
5 Starting and stopping the container
docker start 容器id     # 启动容器
docker restart 容器id   # 重启容器
docker stop 容器id      # 停止当前正在运行的容器
docker kill 容器id      # 杀死当前正在运行的容器

Chapter 11

Guess you like

Origin blog.csdn.net/lzyaks/article/details/128622212