使用 Dockerfile 制作镜像
2.10.1. 基于 Dockerfile 创建镜像
为什么要自己创建镜像呢? 因为官方提供的镜像无法满足我们的需求,例如 nginx 镜像你会发现 ps, top 等等很多命令缺失。
2.10.1.1. 创建 Dockerfile 文件
需求基于centos7镜像创建nginx stable最新版本镜像
############################################################ # Dockerfile to build Nginx container # Based on centos7 ############################################################ FROM centos:latest MAINTAINER Netkiller <[email protected]> # Install EPEL RUN yum install -y epel-release && yum clean all # Update RPM Packages RUN yum -y update # Install Nginx RUN rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm RUN yum install -y nginx RUN yum clean all # forward request and error logs to docker log collector RUN ln -sf /dev/stdout /var/log/nginx/access.log RUN ln -sf /dev/stderr /var/log/nginx/error.log # be backwards compatible with pre-official images #RUN ln -sf ../share/nginx /usr/local/nginx # prepare container # add startup script #ADD startup.sh /startup.sh #RUN chmod 755 /startup.sh VOLUME ["/etc/nginx"] VOLUME ["/usr/share/nginx/html"] VOLUME ["/var/www"] EXPOSE 80 443 CMD ["nginx", "-g", "daemon off;"]
2.10.1.2. 创建镜像
# docker build -t "centos:nginx" . Sending build context to Docker daemon 3.072 kB Step 1/14 : FROM centos:latest ---> 3bee3060bfc8 Step 2/14 : MAINTAINER Netkiller <[email protected]> ---> Using cache ---> 8f351964d568 Step 3/14 : RUN yum install -y epel-release && yum clean all ---> Using cache ---> bf86eff77ff3 Step 4/14 : RUN yum -y update ---> Using cache ---> 4915172ac4f3 Step 5/14 : RUN rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm ---> Using cache ---> 4a919bd141c9 Step 6/14 : RUN yum install -y nginx ---> Using cache ---> 2718221eab8c Step 7/14 : RUN yum clean all ---> Using cache ---> 62231a5f1d76 Step 8/14 : RUN ln -sf /dev/stdout /var/log/nginx/access.log ---> Using cache ---> 38be8f0cc782 Step 9/14 : RUN ln -sf /dev/stderr /var/log/nginx/error.log标签:RUN,log,制作,---,nginx,Step,yum,镜像,Dockerfile From: https://blog.csdn.net/u010604770/article/details/142846158