目 录CONTENT

文章目录

Dockerfile构建镜像参考

所念皆星河
2024-01-08 / 0 评论 / 0 点赞 / 39 阅读 / 1462 字

1.创建存储Dockerfile文件的目录

 mkdir docker_builder
 cd /root/docker_builder/

2.下载需要的包

 wget http://nginx.org/download/nginx-1.8.1.tar.gz
 wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

3.编写Dockerfile文件

cd /root/docker_builder/ vim Dockerfile

# This my first nginx Dockerfile
# Version 1.0
 
# Base images 基础镜像
FROM centos
 
#MAINTAINER 维护者信息
MAINTAINER zhujingzhi
 
#ENV 设置环境变量
ENV PATH /usr/local/nginx/sbin:$PATH
 
#ADD  文件放在当前目录下,拷过去会自动解压
ADD nginx-1.8.1.tar.gz /usr/local/
ADD epel-release-7-11.noarch.rpm /usr/local/
 
 
#RUN 执行以下命令
RUN rpm -ivh /usr/local/epel-release-7-11.noarch.rpm
RUN yum install -y wget lftp gcc gcc-c++ make openssl-devel pcre-devel pcre && yum clean all
RUN useradd -s /sbin/nologin -M nginx
 
#WORKDIR 相当于cd
WORKDIR /usr/local/nginx-1.8.1
 
RUN ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-pcre && make && make install
 
RUN ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
 
#EXPOSE 映射端口
EXPOSE 80
 
#CMD 运行以下命令
CMD ["nginx","-g","daemon off;"]

4.构建镜像

 cd /root/docker_builder/
 docker build -t zhujingzhi/nginx1.8.1 .
0

评论区