$ docker --helpCommands:ps            列出容器列表logs          输出当前容器日志信息port          查看映射端口对应的容器内部源端口images        列出镜像diff          检查容器文件系统上的更改events        从服务器获取实时事件history       查看一个镜像历史info          显示系统相关信息inspect       查看容器详细信息top           查看容器中运行的进程信息Version       查看 docker 版本号wait          查看容器停止时的退出状态值attach        当前 shell 下 attach 连接指定运行镜像cp            从容器中拷贝指定文件或者目录到宿主机中create        创建一个新的容器,同 run,但不启动容器exec          在已存在的容器上运行命令export        导出容器的内容流作为一个 tar 归档文件kill          kill 指定 docker 容器pause         暂停容器rename        容器重命名restart       重启运行的容器rm            移除一个或者多个容器run           创建一个新的容器并运行start         启动容器stats         显示容器的实时流资源使用统计信息stop          停止容器tag           给源中镜像打标签unpause       取消暂停容器Update        更新一个或多个容器的配置load          从一个 tar 包中加载一个镜像pull          从docker镜像源服务器拉取指定镜像push          推送指定镜像或者库镜像至docker源服务器import        从tar包中的内容创建一个新的文件系统映像search        在 docker hub 中搜索镜像rmi           移除一个或多个镜像[无容器使用该镜像才可删除,否则需删除相关容器才可继续或 -f 强制删除]build         通过 Dockerfile 定制镜像commit        提交当前容器为新的镜像save          保存一个镜像为一个 tar 包[对应 load]login         注册或者登陆一个 docker 源服务器logout        从当前 Docker registry 退出

例子:

1.查看docker信息

root@db4:~# docker infoContainers: 7 Running: 2 Paused: 0 Stopped: 5Images: 3Server Version: 17.03.1-ceStorage Driver: aufs Root Dir: /var/lib/docker/aufs Backing Filesystem: extfs Dirs: 44 Dirperm1 Supported: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins: Volume: local Network: bridge host macvlan null overlaySwarm: inactiveRuntimes: runc...此处省略

2.查看镜像和容器列表

root@db4:~# docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEroot@db4:~# docker psCONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                NAMES

3.运行容器

root@db4:~# docker run -d -p 80:80 registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14B96812081345e323933cebe0c3e4b624e62ba673ee51647c6aca6c8cca4bb80froot@db4:~# docker imagesREPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZEregistry.cn-hangzhou.aliyuncs.com/jonny/nginx   1.9.14              54f500f03701        8 months ago        236 MBroot@db4:~# docker psCONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                NAMESb96812081345        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   23 seconds ago      Up 22 seconds       0.0.0.0:80->80/tcp   sad_babbage # docker run 参数:-d 后台运行 -p 端口映射 -p=“80:80”-v 目录挂载 -v=“宿主机路径:容器路径”-w 创建工作目录 -w=“宿主机路径”-h 指定容器的主机名 -h=“主机名”

访问:

图片.png

4.查看容器信息

# 对容器操作有两个对象: 容器ID和容器名称。 # 查看容器所有信息 docker inspect b8f76748becc   docker inspect sad_babbage # 根据条件查看某字段 root@db4:~# docker inspect -f '{
{.NetworkSettings.Networks.bridge.IPAddress}}'  b8f76748becc172.17.0.3

5.容器操作:停止、启动、重启容器、kill

root@db4:~# docker psCONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                NAMESb96812081345        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   32 minutes ago      Up 32 minutes       0.0.0.0:80->80/tcp   sad_babbage root@db4:~# docker port b9680/tcp -> 0.0.0.0:80 root@db4:~# docker stop b96b96root@db4:~# docker ps CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMESroot@db4:~# docker ps -a CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS                      PORTS               NAMESb96812081345        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   32 minutes ago      Exited (0) 9 seconds ago                        sad_babbage root@db4:~# docker wait b960root@db4:~# docker start b96b96root@db4:~# docker ps CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                NAMESb96812081345        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   34 minutes ago      Up 4 seconds        0.0.0.0:80->80/tcp   sad_babbageroot@db4:~# docker restart b96b96root@db4:~# docker kill b96b96 root@db4:~# docker ps -aCONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS                        PORTS               NAMESb96812081345        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   36 minutes ago      Exited (137) 10 seconds ago                       sad_babbage

6.创建容器,但不运行

root@db4:~# docker create registry.cn-hangzhou.aliyuncs.com/jonny/nginx:v2.0bc1a0887280df3494313007c512d30319828c377cd03dc3f6799ac5b6deace0aroot@db4:~# docker ps -aCONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS                         PORTS                            NAMESbc1a0887280d        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:v2.0     "/usr/bin/supervisord"   21 seconds ago      Created                                                         relaxed_swanson b8f76748becc        e8b                                                    "/usr/bin/supervisord"   About an hour ago   Up About an hour               80/tcp, 0.0.0.0:8080->8080/tcp   nginx_8080b96812081345        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   2 hours ago         Exited (0) About an hour ago                                    sad_babbage root@db4:~#

7.查看容器的日志

root@db4:~# docker logs  b96/usr/lib/python2.7/site-packages/supervisor/options.py:296: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.  'Supervisord is running as root and it is searching '2017-05-24 14:37:08,664 CRIT Supervisor running as root (no user in config file)2017-05-24 14:37:08,664 WARN Include ed extra file "/etc/supervisor.d/supervisord.ini" during parsing2017-05-24 14:37:08,675 INFO RPC interface 'supervisor' initialized2017-05-24 14:37:08,675 CRIT Server 'unix_http_server' running without any HTTP authentication checking2017-05-24 14:37:08,675 INFO supervisord started with pid 12017-05-24 14:37:09,680 INFO spawned: 'nginx' with pid 72017-05-24 14:37:09,683 INFO spawned: 'crond' with pid 82017-05-24 14:37:10,722 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)2017-05-24 14:37:10,722 INFO success: crond entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)# -f 跟踪日志类似于linux 命令的tail –f

8.删除容器

root@db4:~# docker ps -aCONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS                         PORTS                            NAMESb8f76748becc        e8b                                                    "/usr/bin/supervisord"   9 minutes ago       Up 9 minutes                   80/tcp, 0.0.0.0:8080->8080/tcp   sharp_pasteur b96812081345        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   55 minutes ago      Up 9 minutes                   0.0.0.0:80->80/tcp               sad_babbage 865ce2a32e57        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   56 minutes ago      Created                                                         trusting_heisenberg 4ffd4bc6cb1c        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   56 minutes ago      Exited (0) 56 minutes ago                                       suspicious_franklin ff44d0a5295a        54f500f03701                                           "/usr/bin/supervisord"   58 minutes ago      Exited (0) 56 minutes ago                                       nervous_noyce 7cb320d7a6e1        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   About an hour ago   Exited (0) 58 minutes ago                                       blissful_jepsen 1f69c23f6450        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   About an hour ago   Exited (0) About an hour ago                                    eloquent_lichterman # 删除单个容器 (已经停止的容器) root@db4:~# docker rm 865ce2a32e57865ce2a32e57 # 删除所有容器 root@db4:~# docker rm $(docker ps -a -q)4ffd4bc6cb1cff44d0a5295a7cb320d7a6e1root@db4:~# docker ps -aCONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                            NAMESb8f76748becc        e8b                                                    "/usr/bin/supervisord"   11 minutes ago      Up 11 minutes       80/tcp, 0.0.0.0:8080->8080/tcp   sharp_pasteur b96812081345        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   58 minutes ago      Up 11 minutes       0.0.0.0:80->80/tcp               sad_babbage

9.进入容器

root@db4:~# docker run -d -i -t registry.cn-hangzhou.aliyuncs.com/jonny/python:3 "/bin/sh"7799fac95d9e13414bdee56013d2521968bf671e3706043f85fa66e343cf431droot@db4:~# docker psCONTAINER ID        IMAGE                                              COMMAND             CREATED             STATUS                  PORTS               NAMES7799fac95d9e        registry.cn-hangzhou.aliyuncs.com/jonny/python:3   "/bin/sh"           1 second ago        Up Less than a second                       elegant_raman root@db4:~# docker attach 779# # ls bin  boot  core  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var # exitroot@db4:~# docker psCONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMESDocker exec -d 执行指令 -i 交互 -t 终端 root@db4:~# docker exec -d  b96  touch /root/exec.logroot@db4:~# docker exec b96 ls /root/exec.logroot@db4:~# docker exec -it b96 sh / # pwd /

10.从容器中拷贝文件到本地和从本地拷贝文件到容器

root@db4:~# docker psCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMESb8f76748becc        e8b                 "/usr/bin/supervisord"   About an hour ago   Up About an hour    80/tcp, 0.0.0.0:8080->8080/tcp   sharp_pasteur root@db4:~# docker rename b8f nginx_8080root@db4:~# docker psCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMESb8f76748becc        e8b                 "/usr/bin/supervisord"   About an hour ago   Up About an hour    80/tcp, 0.0.0.0:8080->8080/tcp   nginx_8080

11.容器重命名

root@db4:~# docker psCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMESb8f76748becc        e8b                 "/usr/bin/supervisord"   About an hour ago   Up About an hour    80/tcp, 0.0.0.0:8080->8080/tcp   sharp_pasteur root@db4:~# docker rename b8f nginx_8080root@db4:~# docker psCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMESb8f76748becc        e8b                 "/usr/bin/supervisord"   About an hour ago   Up About an hour    80/tcp, 0.0.0.0:8080->8080/tcp   nginx_8080

12.暂停容器

root@db4:~# docker pause b8fb8f暂停着服务不可用。 root@db4:~# docker ps CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                            NAMESb8f76748becc        e8b                 "/usr/bin/supervisord"   About an hour ago   Up About an hour (Paused)   80/tcp, 0.0.0.0:8080->8080/tcp   sharp_pasteur root@db4:~# docker unpause b8fb8froot@db4:~# docker ps CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMESb8f76748becc        e8b                 "/usr/bin/supervisord"   About an hour ago   Up About an hour    80/tcp, 0.0.0.0:8080->8080/tcp   sharp_pasteur
13.查看容器进程
root@db4:~# docker top b96UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMDroot                45233               45216               0                   17:13               ?                   00:00:00            /usr/bin/python /usr/bin/supervisord root                45257               45233               0                   17:13               ?                   00:00:00            nginx: master process /usr/local/nginx/sbin/nginx -g daemon off;root                45258               45233               0                   17:13               ?                   00:00:00            /usr/sbin/crond -f -L /usr/local/nginx/logs/crond.lognobody              45259               45257               0                   17:13               ?                   00:00:00            nginx: worker process

13.查看容器的实时资源使用情况

root@db4:~# docker stats b8fCONTAINER           CPU %               MEM USAGE / LIMIT       MEM %               NET I/O             BLOCK I/O           PIDSb8f                 0.19%               3.602 MiB / 974.9 MiB   0.37%               3.27 kB / 3.2 kB    1.62 MB / 8.19 kB   4

14.查看docker 事件

# 事先执行docker events   root@db4:~# docker events  # 在另外一个终端对容器进行操作 root@db4:~# docker stop b96b96root@db4:~# docker restart b96b96root@db4:~# docker events 2017-05-24T17:41:26.703418212+08:00 container kill b96812081345e323933cebe0c3e4b624e62ba673ee51647c6aca6c8cca4bb80f (image=registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14, name=sad_babbage, signal=15)2017-05-24T17:41:26.754823179+08:00 container die b96812081345e323933cebe0c3e4b624e62ba673ee51647c6aca6c8cca4bb80f (exitCode=0, image=registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14, name=sad_babbage)2017-05-24T17:41:26.830372248+08:00 network disconnect 074ed6cf0e44bf95ade6f4f8b3c18781fc9fd65eab8481e064e2669a72e14e29 (container=b96812081345e323933cebe0c3e4b624e62ba673ee51647c6aca6c8cca4bb80f, name=bridge, type=bridge)2017-05-24T17:41:26.868053643+08:00 container stop b96812081345e323933cebe0c3e4b624e62ba673ee51647c6aca6c8cca4bb80f (image=registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14, name=sad_babbage)2017-05-24T17:41:33.871581991+08:00 network connect 074ed6cf0e44bf95ade6f4f8b3c18781fc9fd65eab8481e064e2669a72e14e29 (container=b96812081345e323933cebe0c3e4b624e62ba673ee51647c6aca6c8cca4bb80f, name=bridge, type=bridge)2017-05-24T17:41:34.188260322+08:00 container start b96812081345e323933cebe0c3e4b624e62ba673ee51647c6aca6c8cca4bb80f (image=registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14, name=sad_babbage)2017-05-24T17:41:34.188318535+08:00 container restart b96812081345e323933cebe0c3e4b624e62ba673ee51647c6aca6c8cca4bb80f (image=registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14, name=sad_babbage)

15.查看容器文件的增、删、改

root@db4:~# docker exec -it b96 sh  / # touch /tmp/diff.log/ # exitroot@db4:~# docker diff b96C /rootA /root/.ash_history A /root/.bash_history A /root/.viminfo C /runA /run/supervisord.sock A /supervisord.pid C /tmp A /tmp/crond-stderr---supervisor-lJb_zr.logA /tmp/crond-stdout---supervisor-K8nnKW.logA /tmp/diff.log… Symbol  DescriptionA       A file or directory was addedD       A file or directory was deletedC       A file or directory was changed

16.拉取镜像

Docker官网镜像地址:https://hub.docker.com/explore/阿里云镜像地址:https://cs.console.aliyun.com/#/repo root@db4:~# docker pull registry.cn-hangzhou.aliyuncs.com/jonny/mysql:5.65.6: Pulling from jonny/mysql 8b87079b7a06: Pull complete a3ed95caeb02: Pull complete …Digest: sha256:f74beade896c31cf9725eb567f813d18a3e8cffdab252eca8c6ce6c4337d1443Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/jonny/mysql:5.6

17.搜索镜像

root@db4:~# docker search nginx NAME                                     DESCRIPTION                                     STARS     OFFICIAL   AUTOMATEDnginx                                    Official build of Nginx.                        6058      [OK]       jwilder/nginx-proxy                      Automated Nginx reverse proxy for docker c...   1032                 [OK]richarvey/nginx-php-fpm                  Container running Nginx + PHP-FPM capable ...   379                  [OK]jrcs/letsencrypt-nginx-proxy-companion   LetsEncrypt container to use with nginx as...   181                  [OK]…

18.提交新镜像

root@db4:~# docker exec -it b96 sh

/ # cd /usr/local/nginx/conf/

/usr/local/nginx/conf # grep 8080 nginx.conf

        listen       8080;

root@db4:~# docker commit b96 nginx:v2.0

sha256:e8b6bdca34fdd6e859ac794cefd14890c1a6a3d7514f10f9b85884fc4c782888

root@db4:~# docker run -d -p 8080:8080 e8b

b8f76748becc122df22d887f5eb7d503dd837126937f450d3c05a47641eb587f

访问:

图片.png

19.推送镜像阿里云仓库

root@db4:~# docker login --username=jy1779@163.com registry.cn-hangzhou.aliyuncs.comPassword: Login Succeededroot@db4:~# docker imagesREPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZEnginx                                            latest              aaf9cb9f4204        11 minutes ago      236 MBnginx                                            v2.0                e8b6bdca34fd        About an hour ago   236 MBregistry.cn-hangzhou.aliyuncs.com/jonny/nginx    1.9.14              54f500f03701        8 months ago        236 MBregistry.cn-hangzhou.aliyuncs.com/jonny/python   3                   7918f1fa1b61        10 months ago       686 MBroot@db4:~# docker tag nginx:v2.0 registry.cn-hangzhou.aliyuncs.com/jonny/nginx:v2.0  root@db4:~# docker push registry.cn-hangzhou.aliyuncs.com/jonny/nginx:v2.0 The push refers to a repository [registry.cn-hangzhou.aliyuncs.com/jonny/nginx]ee1ec61f5876: Pushed e4c220924fcf: Layer already exists 880a03e21e97: Layer already exists 8c2d24778f16: Layer already exists 58d1bd0fe6cd: Layer already exists f3e31263e373: Layer already exists 43d68a309658: Layer already exists 4aa9a6e6b176: Layer already exists fb4d779f7310: Layer already exists 5507160a5e67: Layer already exists 251680350a8e: Layer already exists 44e66153e719: Layer already exists 3fc666989c1d: Layer already exists v2.0: digest: sha256:17fcbb1ba3cebee0146beb56193c84565d28b3eac5d9c92d9d51efff52a837db size: 3046root@db4:~# docker logout registry.cn-hangzhou.aliyuncs.comRemoving login credentials for registry.cn-hangzhou.aliyuncs.com

查看:

图片.png

20.删除镜像

root@db4:~# docker imagesREPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZEnginx                                           v2.0                e8b6bdca34fd        14 minutes ago      236 MBregistry.cn-hangzhou.aliyuncs.com/jonny/nginx   1.9.14              54f500f03701        8 months ago        236 MBregistry.cn-hangzhou.aliyuncs.com/jonny/mysql   5.6                 73e25e0ad5a6        12 months ago       325 MBroot@db4:~# docker rmi  73e25e0ad5a6Untagged: registry.cn-hangzhou.aliyuncs.com/jonny/mysql:5.6Untagged: registry.cn-hangzhou.aliyuncs.com/jonny/mysql@sha256:f74beade896c31cf9725eb567f813d18a3e8cffdab252eca8c6ce6c4337d1443Deleted: sha256:73e25e0ad5a687089694c06268cf13d4479cfeafe35e34bdd6aebc5419b5fc10Deleted: sha256:6523d35a3424f7608e39c6aa4665a7524bccf39f56d5ade4644541dc6521d917Deleted: sha256:cc21027dfe1dd9e4ea85ef9b2cfa19d68f533bcacf2929b0180fe8ad719d75f0Deleted: sha256:bff752fe4a4634c1d5b0e9ea864aa02120955c44fc916e1c064bf690b8e1b417Deleted: sha256:3fe3543590e576687bee1ba4ab19f861a5ebd02b0500447e398cd5e6a9c93d0eDeleted: sha256:26c54fc486bc69cf7ce868d0150aee14d9a9b2c2dac49e353329ef4b313d0974Deleted: sha256:0fdf917ab45866188e063827bcabe458e0f34a4b605ff14b3e166bc4258e2693Deleted: sha256:4bdcc159819904f7f87657bb38afa79c99467a2ed84f228acd8c65b17f0deeb6Deleted: sha256:fddaf298f07ba02349d9450c79f142e5b1c5ef291363e1a7a30a2074fc7f7122Deleted: sha256:1f0d2eab171a3acee8114f2625538f5b7ff06f1a4d6d981a51759e5e2c51ce91Deleted: sha256:111f35b1ed9c5131cdfa0a7919bc31e946eafbcefc3b15add943a40a1a76ae15Deleted: sha256:373d98e5699867dd4419c9cc8935e235c7db8c61497493e87faee459088f1f3cDeleted: sha256:1290b53396d9d123f46d81430b0f4ca1e5163f117be22a1e48c72a252e8980b7Deleted: sha256:e6973fa144250a55057571ed5b0c5fa815fb136ba54ade10e01633aa398cdacbDeleted: sha256:ef9f86c3f5e7cad05a0a558a1ad1a601b3b5511e21b50e70b517e13a0f62938fDeleted: sha256:f5e12e98d7fb314c46673c0f4a14326eeca08a9dc7f9ea82e10e39d85c74900aDeleted: sha256:f7cf774ed4094c199f554927b7b01690920b834f118e702ff2643560549f27fcDeleted: sha256:6eb35183d3b8bb6aee54874076fb1ad77b5259c93b330986b0cbcaa44cbbbc00root@db4:~# docker imagesREPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZEnginx                                           v2.0                e8b6bdca34fd        16 minutes ago      236 MBregistry.cn-hangzhou.aliyuncs.com/jonny/nginx   1.9.14              54f500f03701        8 months ago        236 MB

21.保存镜像和载入镜像

# 将一个镜像保存为一个镜像文件。 root@db4:~# docker save -o nginx_v2.0.tar nginx:v2.0 root@db4:~# ls nginx_v2.0.tar# 将一个镜像文件载入为镜像。 root@db4:~# docker load --input nginx_v2.0.tar或 root@db4:~# docker load < nginx_v2.0.tar

22.导出容器和导入镜像

将一个正在运行或者停止的容器导出为一个容器文件 root@db4:~#  docker export b96 > nginx.tarroot@db4:~# ls nginx.tar将一个容器文件导入到本地镜像仓库 root@db4:~# docker import nginx.tar nginx sha256:aaf9cb9f42047c24be3178c9205323175c0b872b3a695314e22ce1d432caa501root@db4:~# docker imagesREPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZEnginx                                           latest              aaf9cb9f4204        8 seconds ago       236 MBnginx                                           v2.0                e8b6bdca34fd        About an hour ago   236 MBregistry.cn-hangzhou.aliyuncs.com/jonny/nginx   1.9.14              54f500f03701        8 months ago        236 MB

23.构建镜像

root@db4:~# touch Dockerfile root@db4:~# vim Dockerfile root@db4:~# cat Dockerfile FROM registry.cn-hangzhou.aliyuncs.com/jonny/python:3root@db4:~# docker build .Sending build context to Docker daemon 490.1 MBStep 1/1 : FROM registry.cn-hangzhou.aliyuncs.com/jonny/python:33: Pulling from jonny/python5c90d4a2d1a8: Pull complete a3ed95caeb02: Pull complete 7aacfb932892: Pull complete 29b0204e3e44: Pull complete f7b3449113d2: Pull complete 4696148a3d89: Pull complete a65fc447ceea: Pull complete eebbb7c52ba8: Pull complete Digest: sha256:e047386633dad2226fbdb5d01f138cf648a6245ef1250e9d1a34e7c95454fda2Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/jonny/python:3 ---> 7918f1fa1b61Successfully built 7918f1fa1b61root@db4:~# docker imagesREPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZEnginx                                            latest              aaf9cb9f4204        7 minutes ago       236 MBnginx                                            v2.0                e8b6bdca34fd        About an hour ago   236 MBregistry.cn-hangzhou.aliyuncs.com/jonny/nginx    1.9.14              54f500f03701        8 months ago        236 MBregistry.cn-hangzhou.aliyuncs.com/jonny/python   3                   7918f1fa1b61        10 months ago       686 MB

24.查看镜像的历史

root@db4:~# docker history nginx:v2.0IMAGE               CREATED             CREATED BY                                      SIZE                COMMENTe8b6bdca34fd        2 hours ago         /usr/bin/supervisord                            6.69 kB             54f500f03701        8 months ago        /bin/sh -c #(nop) CMD ["/usr/bin/superviso...   0 B                 
           8 months ago        /bin/sh -c echo "55       23       *      ...   85 B                
           8 months ago        /bin/sh -c apk add logrotate supervisor vi...   68.5 MB             
           8 months ago        /bin/sh -c tar -xzvf nginx-${NGINX_VERSION...   35.6 MB             
           8 months ago        /bin/sh -c git clone https://github.com/ya...   1.06 MB             
           8 months ago        /bin/sh -c git clone https://github.com/ap...   285 kB              
           8 months ago        /bin/sh -c git clone https://github.com/ya...   865 kB              
           8 months ago        /bin/sh -c git clone https://github.com/cu...   164 kB              
           8 months ago        /bin/sh -c wget -c http://nginx.org/downlo...   908 kB              
           8 months ago        /bin/sh -c mkdir -p /var/run/nginx/             0 B                 
           8 months ago        /bin/sh -c #(nop) ENV NGINX_VERSION=1.9.14      0 B                 
           8 months ago        /bin/sh -c apk add --no-cache --virtual .b...   123 MB              
           8 months ago        /bin/sh -c wget http://sh.xiayu.site/mirro...   674 kB              
           8 months ago        /bin/sh -c #(nop) ADD file:fd71807f3b22f7f...   4.8 MB