简单说,Docker镜像是一个不包含Linux内核而又精简的Linux操做系统。php
Docker Hub是由Docker公司负责维护的公共注册中心,包含大量的容器镜像,Docker工具默认从这个公共镜像库下载镜像。html
https://hub.docker.com/explorenode
默认是国外的源,下载会慢,能够国内的源提供下载速度:python
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://04be47cf.m.daocloud.io
当咱们启动一个新的容器时,Docker会加载只读镜像,并在其之上添加一个读写层,并将镜像中的目录复制一份到/var/lib/docker/aufs/mnt/容器ID为目录下,咱们可使用chroot进入此目录。若是运行中的容器修改一个已经存在的文件,那么会将该文件从下面的只读层复制到读写层,只读层的这个文件就会覆盖,但还存在,这就实现了文件系统隔离,当删除容器后,读写层的数据将会删除,只读镜像不变。mysql
docker相关文件存放在:/var/lib/docker目录下linux
/var/lib/docker/aufs/diff # 每层与其父层之间的文件差别nginx
/var/lib/docker/aufs/layers/ # 每层一个文件,记录其父层一直到根层之间的IDsql
/var/lib/docker/aufs/mnt # 联合挂载点,从只读层复制到最上层可读写层的文件系统数据docker
在创建镜像时,每次写操做,都被视做一种增量操做,即在原有的数据层上添加一个新层;因此一个镜像会有若干个层组成。ubuntu
每次commit提交就会对产生一个ID,就至关于在上一层有加了一层,能够经过这个ID对镜像回滚
docker images
[bigberg@localhost ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest f2a91732366c 3 months ago 1.85kB
选项说明:
REPOSTITORY:表示镜像的仓库源
TAG:镜像的标签
IMAGE ID:镜像ID
CREATED:镜像建立时间
SIZE:镜像大小
同一仓库源能够有多个 TAG,表明这个仓库源的不一样个版本,如ubuntu仓库源里,有15.十、14.04等多个不一样的版本,咱们使用 REPOSTITORY:TAG 来定义不一样的镜像。
语法:
docker search [OPTIONS] TERM
选项说明:
--automated :只列出 automated build类型的镜像;
--no-trunc :显示完整的镜像描述;
-s :列出收藏数不小于指定值的镜像。
[bigberg@localhost ~]$ docker search centos NAME DESCRIPTION STARS OFFICIAL AUTOMATED centos The official build of CentOS. 4051 [OK] ansible/centos7-ansible Ansible on Centos7 105 [OK] jdeathe/centos-ssh CentOS-6 6.9 x86_64 / CentOS-7 7.4.1708 x86_… 91 [OK] consol/centos-xfce-vnc Centos container with "headless" VNC session… 45 [OK] imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 38 [OK] tutum/centos Simple CentOS docker image with SSH access 36 gluster/gluster-centos Official GlusterFS Image [ CentOS-7 + Glust… 22 [OK] centos/python-35-centos7 Platform for building and running Python 3.5… 18 openshift/base-centos7 A Centos7 derived base image for Source-To-I… 17 kinogmt/centos-ssh CentOS with SSH 17 [OK] openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use w… 10 centos/postgresql-96-centos7 PostgreSQL is an advanced Object-Relational … 7 openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6 pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag names… 3 darksheer/centos Base Centos Image -- Updated hourly 3 [OK] openshift/jenkins-1-centos7 DEPRECATED: A Centos7 based Jenkins v1.x ima… 3 openshift/wildfly-101-centos7 A Centos7 based WildFly v10.1 image for use … 3 pivotaldata/centos Base centos, freshened up a little with a Do… 1 miko2u/centos6 CentOS6 日本語環境 1 [OK] pivotaldata/centos-mingw Using the mingw toolchain to cross-compile t… 1 openshift/php-55-centos7 DEPRECATED: A Centos7 based PHP v5.5 image f… 1 blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK] jameseckersall/sonarr-centos Sonarr on CentOS 7 0 [OK] pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated wi… 0 smartentry/centos centos with smartentry 0 [OK]
咱们可使用 Docker 镜像加速器来解决这个问题,加速器就是镜像、代理的概念。国内有很多机构提供了免费的加速器以方便你们使用,这里列出一些经常使用的加速器服务:
https://registry.docker-cn.com
便可。https://docker.mirrors.ustc.edu.cn/
配置加速器便可。进一步的信息能够访问:http://mirrors.ustc.edu.cn/help/dockerhub.html?highlight=dockerDaoCloud
帐户(支持微信登陆),而后访问: https://www.daocloud.io/mirror#accelerator-doc Ubuntu 16.04
和 CentOS 7
这类系统都已经开始使用 systemd
进行系统初始化管理了,对于使用 systemd
的系统,应该经过编辑服务配置文件 docker.service
来进行加速器的配置。
sudo vim /etc/systemd/system/multi-user.target.wants/docker.service #在文件中找到 ExecStart= 这一行,而且在其行尾添加上所需的配置。假设咱们的加速器地址为 https://registry.docker-cn.com,那么能够这样配置 ExecStart=/usr/bin/dockerd --registry-mirror=https://registry.docker-cn.com sudo systemctl daemon-reload sudo systemctl restart docker # 确认配置 sudo ps -ef | grep dockerd
[bigberg@localhost ~]$ ps -ef | grep docker root 4273 1 1 10:04 ? 00:00:08 /usr/bin/dockerd --registry-mirror=https://registry.docker-cn.com
[bigberg@localhost ~]$ docker pull centos:7 7: Pulling from library/centos af4b0a2388c6: Pull complete Digest: sha256:2671f7a3eea36ce43609e9fe7435ade83094291055f1c96d9d1d1d7c0b986a5d Status: Downloaded newer image for centos:7
[bigberg@localhost ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest e548f1a579cf 3 days ago 109MB centos 7 ff426288ea90 6 weeks ago 207MB hello-world latest f2a91732366c 3 months ago 1.85kB
[bigberg@localhost ~]$ docker save -o centos.tar.gz centos [bigberg@localhost ~]$ docker save nginx > nginx.tar.gz [bigberg@localhost ~]$ docker image save hello-world > hello.tar.gz [bigberg@localhost ~]$ ll total 320480 -rw------- 1 bigberg bigberg 215760384 Feb 24 10:38 centos.tar.gz -rw-rw-r-- 1 bigberg bigberg 12800 Feb 24 10:40 hello.tar.gz -rw-rw-r-- 1 bigberg bigberg 112393728 Feb 24 10:39 nginx.tar.gz
[root@linux-node1 ~]#docker load --input centos.tar.gz #使用input导入 [root@linux-node1 ~]# docker load < nginx.tar.gz #使用重定向导入 [root@linux-node1 ~]# docker load < /opt/centos.tar.gz #导入本地镜像到docker镜像库
# docker rmi TMAGE ID
[bigberg@localhost ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest e548f1a579cf 3 days ago 109MB centos 7 ff426288ea90 6 weeks ago 207MB hello-world latest f2a91732366c 3 months ago 1.85kB [bigberg@localhost ~]$ docker rmi f2a91732366c Untagged: hello-world:latest Untagged: hello-world@sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751 Deleted: sha256:f2a91732366c0332ccd7afd2a5c4ff2b9af81f549370f7a19acd460f87686bc7 Deleted: sha256:f999ae22f308fea973e5a25b57699b5daf6b0f1150ac2a5c2ea9d7fecee50fdf [bigberg@localhost ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest e548f1a579cf 3 days ago 109MB centos 7 ff426288ea90 6 weeks ago 207MB
能够看到镜像的每一次
-H :以可读的格式打印镜像大小和日期,默认为true;
--no-trunc :显示完整的提交记录;
-q :仅列出提交记录ID。
[bigberg@localhost ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest e548f1a579cf 3 days ago 109MB centos 7 ff426288ea90 6 weeks ago 207MB [bigberg@localhost ~]$ docker -H nginx ^C [bigberg@localhost ~]$ docker history nginx IMAGE CREATED CREATED BY SIZE COMMENT e548f1a579cf 3 days ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B <missing> 3 days ago /bin/sh -c #(nop) STOPSIGNAL [SIGTERM] 0B <missing> 3 days ago /bin/sh -c #(nop) EXPOSE 80/tcp 0B <missing> 3 days ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx… 22B <missing> 3 days ago /bin/sh -c set -x && apt-get update && apt… 53.4MB <missing> 3 days ago /bin/sh -c #(nop) ENV NJS_VERSION=1.13.9.0.… 0B <missing> 3 days ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.13.9-… 0B <missing> 6 days ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B <missing> 9 days ago /bin/sh -c #(nop) CMD ["bash"] 0B <missing> 9 days ago /bin/sh -c #(nop) ADD file:27ffb1ef53bfa3b9f… 55.3MB