1.通过dockerfile 制作centos系统镜像然后再制作 nginx编译镜像
#centos7.7-dockerfile
cat dockerfile
FROM cetos:centos7.7.1908
LABEL maintainer="tyzh<283399535@qq.com>"
FROM centos:centos7.7.1908
LABEL maintainer="tyzh <283399535@qq.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 lso-f 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
#生成centos镜像
docker build -t centos7-base:v1 .
#nginx-dockerfile
wget http://nginx.org/download/nginx-1.18.0.tar.gz
cat dockerfile
FROM centos7-base:v1
LABEL maintainer="tyzh <283399535@qq.com>"
RUN yum -y install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
&& useradd -r -s /sbin/nologin nginx
&& yum clean all
ADD nginx-1.18.0.tar.gz /usr/local/src/
RUN cd /usr/local/src/nginx-1.18.0
&& mkdir -p /apps/nginx
&& ./configure --prefix=/apps/nginx
&& make
&& make install
&& sed -ri 's@#(user )nobody@1nginx@' /apps/nginx/conf/nginx.conf
&& sed -ri 's@(worker_processes )1@1auto@' /apps/nginx/conf/nginx.conf
&& sed -ri '3a daemon off;' /apps/nginx/conf/nginx.conf
&& echo "nginx is running in docker" > /apps/nginx/html/index.html
&& rm -rf /usr/local/nginx*
RUN ln -s /apps/nginx/sbin/nginx /usr/sbin/nginx
EXPOSE 80 443
CMD /usr/sbin/nginx
#生成nginx镜像
docker build -t nginx-centos7:1.18.0-v1 .
#查看镜像
doker images
#生成容器测试镜像
docker run --name nginx -d -p 80:80 nginx-centos7:1.18.0-v1
#测试
curl 172.17.0.2:80
2.写出10个常用的dockerfile 脚本参数及使用说明
FROM 指定基础镜像; LABEL 指定镜像元数据;RUN 执行shell命令;ENV 设置环境变量;CPOY 复制文本;
ADD 复制和解压文件; CMD容器启动命令 ;ENTRYPOINT 入口点;ARG 构建参数;VOLUME 挂载点;
EXPOSE 对外暴露的端口;WORKDIR 指定容器默认目录
3.请写出dockerfile的分层原理
Dockerfile通常会指定基础镜像,这个可以认为是系统层,复制文件、执行命令等操作时会生成新的镜像层,每层只记录本层所做的更改,而这些层都是只读的,当启动一个容器,Docker 会在最顶部添加读写层,用户在容器内做的所有更改,如写日志、修改、删除文件等,都保存到了读写层内,一般称该层为容器层。