实战案例:Dockerfile 制作基于基础镜像的Base镜像
准备目录结构,下载镜像并初始化系统
#按照业务类型或系统类型等方式划分创建目录环境,方便后期镜像比较多的时候进行分类
[root@ubuntu1804 ~]#mkdir /data/dockerfile/{web/{nginx,apache,tomcat,jdk},system/{centos,ubuntu,alpine,debian}} -p
[root@ubuntu1804 ~]#tree /data/dockerfile/
/data/dockerfile/
├── system
│ ├── alpine
│ ├── centos
│ ├── debian
│ └── ubuntu
└── web
├── apache
├── jdk
├── nginx
└── tomcat
10 directories, 0 files
[root@ubuntu1804 ~]#
#下载基础镜像
[root@ubuntu1804 ~]#docker pull centos:centos7.7.1908
[root@ubuntu1804 ~]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos centos7.7.1908 08d05d1d5859 2 months ago 204MB
先制作基于基础镜像的系统Base镜像
#先制作基于基础镜像的系统base镜像
[root@ubuntu1804 ~]#cd /data/dockerfile/system/centos/
#创建Dockerfile,注意可以是dockerfile,但无语法着色功能
[root@ubuntu1804 centos]#vim Dockerfile
[root@ubuntu1804 centos]#cat Dockerfile
FROM centos:centos7.7.1908
LABEL maintainer="wangxiaochun <root@wangxiaochun.com>"
RUN yum -y install wget && rm -f /etc/yum.repos.d/* && wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo /
&& wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo /
&& yum -y install vim-enhanced tcpdump lrzsz tree telnet bash-completion net-tools wget bzip2 lsof zip unzip nfs-utils gcc make gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel /
&& yum clean all /
&& rm -f /etc/localtime /
&& ln -s ../usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@ubuntu1804 centos]#vim build.sh
[root@ubuntu1804 centos]#cat build.sh
#!/bin/bash
#
docker build -t centos7-base:v1 .
[root@ubuntu1804 centos]#chmod +x build.sh
[root@ubuntu1804 centos]#./build.sh
[root@ubuntu1804 centos]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7-base v1 1ba1317e06dc 23 seconds ago 402MB
centos centos7.7.1908 08d05d1d5859 2 months ago 204MB
[root@ubuntu1804 centos]#docker image history centos7-base:v1
IMAGE CREATED CREATED BY SIZE COMMENT
1ba1317e06dc 43 seconds ago /bin/sh -c yum -y install wget && rm -f /etc… 198MB
6b87f2843eb9 About an hour ago /bin/sh -c #(nop) LABEL maintainer=wangxiao… 0B
08d05d1d5859 2 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 2 months ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B
<missing> 2 months ago /bin/sh -c #(nop) ADD file:3e2a127b44ed01afc… 204MB
本文链接:http://www.yunweipai.com/34833.html
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/52662.html