第二章:Docker镜像管理

 第二章:Docker镜像管理

1.镜像与容器联系,存储驱动
  
  
https://hub.docker.com/
https://hub.docker.com/explore/

修改为国内的镜像下载源并重启服务:
[root@linux-node1 ~]# vim /etc/docker/daemon.json
[root@linux-node1 ~]# cat /etc/docker/daemon.json
{
"registry-mirrors":[ "https://registry.docker-cn.com" ]
}

[root@linux-node1 ~]# systemctl restart docker
[root@linux-node1 ~]# ps -ef|grep docker
root 1773 1 0 20:47 ? 00:00:00 /usr/bin/dockerd
root 1777 1773 0 20:47 ? 00:00:00 docker-containerd --config /var/run/docker/containerd/containerd.toml
root 1876 1314 0 20:48 pts/0 00:00:00 grep --color=auto docker

[root@linux-node1 ~]# docker pull nginx:1.12
1.12: Pulling from library/nginx
2a72cbf407d6: Already exists
f37cbdc183b2: Pull complete
78b5ad0b466c: Pull complete
Digest: sha256:fc54f47e6e3721f9b08a478fe00b07920c21eda0bde655c7d82c8cfa4a83986e
Status: Downloaded newer image for nginx:1.12
[root@linux-node1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest b175e7467d66 12 days ago 109MB
nginx 1.12 1b155f07a3fa 5 weeks ago 108MB

  
[root@linux-node1 ~]# docker history nginx:1.12
IMAGE CREATED CREATED BY SIZE COMMENT
1b155f07a3fa 5 weeks ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
<missing> 5 weeks ago /bin/sh -c #(nop) STOPSIGNAL [SIGTERM] 0B
<missing> 5 weeks ago /bin/sh -c #(nop) EXPOSE 80/tcp 0B
<missing> 5 weeks ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx… 22B
<missing> 5 weeks ago /bin/sh -c set -x && apt-get update && apt… 53.1MB
<missing> 5 weeks ago /bin/sh -c #(nop) ENV NJS_VERSION=1.12.2.0.… 0B
<missing> 5 weeks ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.12.2-… 0B
<missing> 5 weeks ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B
<missing> 5 weeks ago /bin/sh -c #(nop) CMD ["bash"] 0B
<missing> 5 weeks ago /bin/sh -c #(nop) ADD file:e3250bb9848f956bd… 55.3MB

存储驱动 管理 实际镜像数据:
[root@linux-node1 ~]# ls /var/lib/docker/overlay2/
33a36e4c1d46ac2d8f29d951213a86308c0b6fbf1f8bd1d117cc946725eb8a9a backingFsBlockDev
5c88f1cad33d32a7f531c1f34303335fb4ed71b0e5a1ed2129531290f25b0930 e4a3cb2aea6f9da2036c5edf416b1800eb436187e3ff4940de6061676b077111
820b144cadc2172071fa0aa79110e313be73c66695dad497fa92eab8930f255a l
a53737074eefc26f9da83fbe66c09eb206985c193219dba30c1807b4f269fbef
  

2.docker镜像管理常用命令
  
[root@linux-node1 ~]# docker --help
Management Commands:
config Manage Docker configs
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes

[root@linux-node1 ~]# docker image --help
Usage: docker image COMMAND
Manage images
Options:
Commands:
build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Run 'docker image COMMAND --help' for more information on a command.

显示所有下载的镜像:
[root@linux-node1 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest b175e7467d66 12 days ago 109MB
nginx 1.12 1b155f07a3fa 5 weeks ago 108MB
显示该镜像分层信息:
[root@linux-node1 ~]# docker image history nginx:1.12
显示该镜像详情:
[root@linux-node1 ~]# docker image inspect nginx:1.12
下载所需镜像:
[root@linux-node1 ~]# docker image pull nginx:1.12
删除镜像:
[root@linux-node1 ~]# docker image rm nginx:1.12
Untagged: nginx:1.12
Untagged: nginx@sha256:fc54f47e6e3721f9b08a478fe00b07920c21eda0bde655c7d82c8cfa4a83986e
Deleted: sha256:1b155f07a3fa149f5f716ec3d8e74c54d33324c5a03da823514294505f016b7c
Deleted: sha256:7f243cb0bb9fc26d7bb855c298c11960a335eaba12d89a15894effb5cc7a5d18
Deleted: sha256:514b0360c9d551993f818887a0dc5ff1099abfc4cf02d95c0d8c8506e71f06a6
[root@linux-node1 ~]# docker image ls
[root@linux-node1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest b175e7467d66 12 days ago 109MB
下载镜像:
[root@linux-node1 ~]# docker pull nginx:1.11
1.11: Pulling from library/nginx
6d827a3ef358: Pull complete
f8f2e0556751: Pull complete
5c9972dca3fd: Pull complete
451b9524cb06: Pull complete
Digest: sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582
Status: Downloaded newer image for nginx:1.11
[root@linux-node1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest b175e7467d66 12 days ago 109MB
nginx 1.11 5766334bdaa0 12 months ago 183MB
给镜像打标签:
[root@linux-node1 ~]# docker tag nginx:1.11 nginx:v1
[root@linux-node1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest b175e7467d66 12 days ago 109MB
nginx 1.11 5766334bdaa0 12 months ago 183MB
nginx v1 5766334bdaa0 12 months ago 183MB
导出镜像:
[root@linux-node1 ~]# docker image save nginx:v1 >/tmp/nginx.tar
[root@linux-node1 ~]# du -sh /tmp/nginx.tar
182M /tmp/nginx.tar
导入镜像:
[root@linux-node1 ~]# docker image load </tmp/nginx.tar
Loaded image: nginx:v1

举例:创建并运行一个容器,-i标准输入、-t分配伪终端、-d守护进程模式运行,--name重命名,导出容器。
[root@linux-node1 ~]# docker run -itd --name mynginx nginx:v1
52a7ae4c65066dc997245226c571416880a1479b94fefeee1a6446b357e0ec55
[root@linux-node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
52a7ae4c6506 nginx:v1 "nginx -g 'daemon of…" 6 seconds ago Up 5 seconds 80/tcp, 443/tcp mynginx
[root@linux-node1 ~]# docker export mynginx >/tmp/mynginx.tar
[root@linux-node1 ~]# du -sh /tmp/mynginx.tar
180M /tmp/mynginx.tar

 

posted @ 2018-04-24 00:25  bkycrmn  阅读(214)  评论(0)    收藏  举报