013、Dockerfile构建镜像(2019-01-02 周三)
Dockerfile构建镜像过程分析
root@docker-lab:~/111# ls # 查看当前目录下存在Dockerfile文件
Dockerfile
root@docker-lab:~/111# cat Dockerfile # 查看Dockerfile问价内容,运行centos容器,然后安装wget命令
FROM centos
RUN yum install -y wget
root@docker-lab:~/111# docker build -t centos-wget . # 执行docker build 命令使用Dockerfile文件构建镜像
Sending build context to Docker daemon 2.048kB # 发送build context(当前目录)下所有文件和子目录到dokcer daemon。建议当前目录不要存放与构建镜像无关的文件,耗时且容易失败
Step 1/2 : FROM centos # 开始运行centos容器
latest: Pulling from library/centos # 从Docker Hub下载centos镜像
a02a4930cb5d: Pull complete
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for centos:latest
---> 1e1148e4cc2c # centos容器启动成功,id:1e1148e4cc2c
Step 2/2 : RUN yum install -y wget # 开始安装wget命令
---> Running in a127bab51f51 # 运行临时容器 a127bab51f51
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirrors.huaweicloud.com
* extras: mirrors.neusoft.edu.cn
* updates: mirrors.neusoft.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
wget x86_64 1.14-18.el7 base 547 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/wget-1.14-18.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for wget-1.14-18.el7.x86_64.rpm is not installed
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-6.1810.2.el7.centos.x86_64 (@CentOS)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : wget-1.14-18.el7.x86_64 1/1
install-info: No such file or directory for /usr/share/info/wget.info.gz
Verifying : wget-1.14-18.el7.x86_64 1/1
Installed:
wget.x86_64 0:1.14-18.el7
Complete!
Removing intermediate container a127bab51f51 # 删除临时容器 a127bab51f51
---> 8486cf558bf9
Successfully built 8486cf558bf9 # 成功构建镜像 8486cf558bf9
Successfully tagged centos-wget:latest
root@docker-lab:~/111# docker images # 查看镜像列表,确认centos-wget 镜像创建成功
REPOSITORY TAG IMAGE ID CREATED SIZE
centos-wget latest 8486cf558bf9 59 seconds ago 272MB
centos latest 1e1148e4cc2c 3 weeks ago 202MB
root@docker-lab:~/111# docker history centos-wget # 查看镜像centos-wget 构建记录,即docker的分层结构
IMAGE CREATED CREATED BY SIZE COMMENT
8486cf558bf9 About a minute ago /bin/sh -c yum install -y wget 70.7MB
1e1148e4cc2c 3 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 3 weeks ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B
<missing> 3 weeks ago /bin/sh -c #(nop) ADD file:6f877549795f4798a… 202MB