docker 经常使用指令

$ docker --help
Commands:
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 退出

例子:php

1.查看docker信息python

root@db4:~# docker info
Containers: 7
 Running: 2
 Paused: 0
 Stopped: 5
Images: 3
Server Version: 17.03.1-ce
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 44
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
...此处省略

2.查看镜像和容器列表mysql

root@db4:~# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
root@db4:~# docker ps
CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                NAMES

3.运行容器linux

root@db4:~# docker run -d -p 80:80 registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14
B96812081345e323933cebe0c3e4b624e62ba673ee51647c6aca6c8cca4bb80f
root@db4:~# docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
registry.cn-hangzhou.aliyuncs.com/jonny/nginx   1.9.14              54f500f03701        8 months ago        236 MB
root@db4:~# docker ps
CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                NAMES
b96812081345        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=“主机名”

访问:nginx

图片.png

4.查看容器信息git

# 对容器操做有两个对象: 容器ID和容器名称。 

# 查看容器全部信息 
docker inspect b8f76748becc   
docker inspect sad_babbage 
# 根据条件查看某字段 
root@db4:~# docker inspect -f '{{.NetworkSettings.Networks.bridge.IPAddress}}'  b8f76748becc
172.17.0.3

5.容器操做:中止、启动、重启容器、killgithub

root@db4:~# docker ps
CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                NAMES
b96812081345        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 b96
80/tcp -> 0.0.0.0:80 
root@db4:~# docker stop b96
b96
root@db4:~# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
root@db4:~# docker ps -a 
CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS                      PORTS               NAMES
b96812081345        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 b96
0
root@db4:~# docker start b96
b96
root@db4:~# docker ps 
CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                NAMES
b96812081345        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_babbage
root@db4:~# docker restart b96
b96
root@db4:~# docker kill b96
b96 
root@db4:~# docker ps -a
CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS                        PORTS               NAMES
b96812081345        registry.cn-hangzhou.aliyuncs.com/jonny/nginx:1.9.14   "/usr/bin/supervisord"   36 minutes ago      Exited (137) 10 seconds ago                       sad_babbage

6.建立容器,但不运行sql

root@db4:~# docker create registry.cn-hangzhou.aliyuncs.com/jonny/nginx:v2.0
bc1a0887280df3494313007c512d30319828c377cd03dc3f6799ac5b6deace0a
root@db4:~# docker ps -a
CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS                         PORTS                            NAMES
bc1a0887280d        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_8080
b96812081345        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.查看容器的日志docker

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 parsing
2017-05-24 14:37:08,675 INFO RPC interface 'supervisor' initialized
2017-05-24 14:37:08,675 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2017-05-24 14:37:08,675 INFO supervisord started with pid 1
2017-05-24 14:37:09,680 INFO spawned: 'nginx' with pid 7
2017-05-24 14:37:09,683 INFO spawned: 'crond' with pid 8
2017-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.删除容器shell

root@db4:~# docker ps -a
CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS                         PORTS                            NAMES
b8f76748becc        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 865ce2a32e57
865ce2a32e57 
# 删除全部容器 
root@db4:~# docker rm $(docker ps -a -q)
4ffd4bc6cb1c
ff44d0a5295a
7cb320d7a6e1
root@db4:~# docker ps -a
CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                            NAMES
b8f76748becc        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"
7799fac95d9e13414bdee56013d2521968bf671e3706043f85fa66e343cf431d
root@db4:~# docker ps
CONTAINER ID        IMAGE                                              COMMAND             CREATED             STATUS                  PORTS               NAMES
7799fac95d9e        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 
# exit
root@db4:~# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Docker exec 
-d 执行指令 
-i 交互 
-t 终端 
root@db4:~# docker exec -d  b96  touch /root/exec.log
root@db4:~# docker exec b96 ls /root/
exec.log
root@db4:~# docker exec -it b96 sh 
/ # pwd 
/

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

root@db4:~# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMES
b8f76748becc        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_8080
root@db4:~# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMES
b8f76748becc        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 ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMES
b8f76748becc        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_8080
root@db4:~# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMES
b8f76748becc        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 b8f
b8f
暂停着服务不可用。 
root@db4:~# docker ps 
CONTAINER
 ID        IMAGE               COMMAND                  
CREATED             STATUS                      
PORTS                            NAMES
b8f76748becc        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 b8f
b8f
root@db4:~# docker ps 
CONTAINER
 ID        IMAGE               COMMAND                  
CREATED             STATUS              PORTS                           
 NAMES
b8f76748becc        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 b96
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                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.log
nobody              45259               45257               0                   17:13               ?                   00:00:00            nginx: worker process

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

root@db4:~# docker stats b8f
CONTAINER           CPU %               MEM USAGE / LIMIT       MEM %               NET I/O             BLOCK I/O           PIDS
b8f                 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 b96
b96
root@db4:~# docker restart b96
b96
root@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
/ # exit
root@db4:~# docker diff b96
C /root
A /root/.ash_history 
A /root/.bash_history 
A /root/.viminfo 
C /run
A /run/supervisord.sock 
A /supervisord.pid 
C /tmp 
A /tmp/crond-stderr---supervisor-lJb_zr.log
A /tmp/crond-stdout---supervisor-K8nnKW.log
A /tmp/diff.log
…
 
Symbol  Description
A       A file or directory was added
D       A file or directory was deleted
C       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.6
5.6: Pulling from jonny/mysql 
8b87079b7a06: Pull complete 
a3ed95caeb02: Pull complete 
…
Digest: sha256:f74beade896c31cf9725eb567f813d18a3e8cffdab252eca8c6ce6c4337d1443
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/jonny/mysql:5.6

17.搜索镜像

root@db4:~# docker search nginx 
NAME                                     DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                                    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.com
Password: 
Login Succeeded
root@db4:~# docker images
REPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZE
nginx                                            latest              aaf9cb9f4204        11 minutes ago      236 MB
nginx                                            v2.0                e8b6bdca34fd        About an hour ago   236 MB
registry.cn-hangzhou.aliyuncs.com/jonny/nginx    1.9.14              54f500f03701        8 months ago        236 MB
registry.cn-hangzhou.aliyuncs.com/jonny/python   3                   7918f1fa1b61        10 months ago       686 MB
root@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: 3046
root@db4:~# docker logout registry.cn-hangzhou.aliyuncs.com
Removing login credentials for registry.cn-hangzhou.aliyuncs.com

查看:

图片.png

20.删除镜像

root@db4:~# docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
nginx                                           v2.0                e8b6bdca34fd        14 minutes ago      236 MB
registry.cn-hangzhou.aliyuncs.com/jonny/nginx   1.9.14              54f500f03701        8 months ago        236 MB
registry.cn-hangzhou.aliyuncs.com/jonny/mysql   5.6                 73e25e0ad5a6        12 months ago       325 MB
root@db4:~# docker rmi  73e25e0ad5a6
Untagged: registry.cn-hangzhou.aliyuncs.com/jonny/mysql:5.6
Untagged: registry.cn-hangzhou.aliyuncs.com/jonny/mysql@sha256:f74beade896c31cf9725eb567f813d18a3e8cffdab252eca8c6ce6c4337d1443
Deleted: sha256:73e25e0ad5a687089694c06268cf13d4479cfeafe35e34bdd6aebc5419b5fc10
Deleted: sha256:6523d35a3424f7608e39c6aa4665a7524bccf39f56d5ade4644541dc6521d917
Deleted: sha256:cc21027dfe1dd9e4ea85ef9b2cfa19d68f533bcacf2929b0180fe8ad719d75f0
Deleted: sha256:bff752fe4a4634c1d5b0e9ea864aa02120955c44fc916e1c064bf690b8e1b417
Deleted: sha256:3fe3543590e576687bee1ba4ab19f861a5ebd02b0500447e398cd5e6a9c93d0e
Deleted: sha256:26c54fc486bc69cf7ce868d0150aee14d9a9b2c2dac49e353329ef4b313d0974
Deleted: sha256:0fdf917ab45866188e063827bcabe458e0f34a4b605ff14b3e166bc4258e2693
Deleted: sha256:4bdcc159819904f7f87657bb38afa79c99467a2ed84f228acd8c65b17f0deeb6
Deleted: sha256:fddaf298f07ba02349d9450c79f142e5b1c5ef291363e1a7a30a2074fc7f7122
Deleted: sha256:1f0d2eab171a3acee8114f2625538f5b7ff06f1a4d6d981a51759e5e2c51ce91
Deleted: sha256:111f35b1ed9c5131cdfa0a7919bc31e946eafbcefc3b15add943a40a1a76ae15
Deleted: sha256:373d98e5699867dd4419c9cc8935e235c7db8c61497493e87faee459088f1f3c
Deleted: sha256:1290b53396d9d123f46d81430b0f4ca1e5163f117be22a1e48c72a252e8980b7
Deleted: sha256:e6973fa144250a55057571ed5b0c5fa815fb136ba54ade10e01633aa398cdacb
Deleted: sha256:ef9f86c3f5e7cad05a0a558a1ad1a601b3b5511e21b50e70b517e13a0f62938f
Deleted: sha256:f5e12e98d7fb314c46673c0f4a14326eeca08a9dc7f9ea82e10e39d85c74900a
Deleted: sha256:f7cf774ed4094c199f554927b7b01690920b834f118e702ff2643560549f27fc
Deleted: sha256:6eb35183d3b8bb6aee54874076fb1ad77b5259c93b330986b0cbcaa44cbbbc00
root@db4:~# docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
nginx                                           v2.0                e8b6bdca34fd        16 minutes ago      236 MB
registry.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.tar
root@db4:~# ls 
nginx.tar
将一个容器文件导入到本地镜像仓库 
root@db4:~# docker import nginx.tar nginx 
sha256:aaf9cb9f42047c24be3178c9205323175c0b872b3a695314e22ce1d432caa501
root@db4:~# docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
nginx                                           latest              aaf9cb9f4204        8 seconds ago       236 MB
nginx                                           v2.0                e8b6bdca34fd        About an hour ago   236 MB
registry.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:3
root@db4:~# docker build .
Sending build context to Docker daemon 490.1 MB
Step 1/1 : FROM registry.cn-hangzhou.aliyuncs.com/jonny/python:3
3: Pulling from jonny/python
5c90d4a2d1a8: 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:e047386633dad2226fbdb5d01f138cf648a6245ef1250e9d1a34e7c95454fda2
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/jonny/python:3
 ---> 7918f1fa1b61
Successfully built 7918f1fa1b61
root@db4:~# docker images
REPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZE
nginx                                            latest              aaf9cb9f4204        7 minutes ago       236 MB
nginx                                            v2.0                e8b6bdca34fd        About an hour ago   236 MB
registry.cn-hangzhou.aliyuncs.com/jonny/nginx    1.9.14              54f500f03701        8 months ago        236 MB
registry.cn-hangzhou.aliyuncs.com/jonny/python   3                   7918f1fa1b61        10 months ago       686 MB

24.查看镜像的历史

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