Dockerfile 构建nginx镜像

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/TZ_GG/article/details/82591191

在公司中,会根据公司特有业务去制作镜像,这种情况下一般使用Dockerfile去构建。

环境准备:一台安装docker服务的服务器即可

Dockerfile是由一行行命令语句组成,支持以#开头的注释
一般而言,Dockerfile分为四部分:基础镜像信息、维护者信息、镜像操作指令和容器启动时执行命令。

详细指令说明可以看我上一篇博客,介绍的有


[[email protected] test]#mkdir -p nginx
[[email protected] test]#cd nginx
[[email protected] nginx]#ls


Dcokerfile
===========================================================================================
# Base images 基础镜像
# 这里的基础镜像用的是阿里云上我自己私仓库里的centos7.5
FROM registry.cn-hangzhou.aliyuncs.com/test/centos:1804 

#MAINTAINER 维护者信息
MAINTAINER test [email protected]

#ENV 设置环境变量
ENV PATH /usr/local/nginx/sbin:$PATH

#RUN 执行指定命令
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && mkdir /yum_back \
    && mv /etc/yum.repos.d/* /yum_back \
    && curl -so /etc/yum.repos.d/centos7-base.repo http://xxx/centos7-base.repo \ #这里用的自己的yum源
    && yum clean all \
    && yum makecache \
    && yum install -y gcc* make pcre-devel pcre zlib-devel openssl-devel \
    && useradd -s /sbin/nologin -M nginx

#ADD  文件放在当前目录下,拷过去会自动解压
ADD nginx-1.15.3.tar.gz /usr/local/ #nginx版本是1.15.3

扫描二维码关注公众号,回复: 3173599 查看本文章

#WORKDIR 指定工作目录 相当于cd
WORKDIR /usr/local/nginx-1.15.3 

RUN ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre && make && make install
RUN ln -s /usr/local/nginx/sbin/* /usr/local/sbin/

#EXPOSE 声明端口
EXPOSE 80

WORKDIR /

#CMD 指定启动容器时执行的命令
RUN nginx
CMD ["nginx", "-g", "daemon off;"]
===========================================================================================

使用build创建
[[email protected] nginx]#docker build -t centos7-nginx:1.15 .


[[email protected] nginx]#docker images
centos7-nginx                                           1.15                48e53719251b        5 days ago          2.72 GB
 

猜你喜欢

转载自blog.csdn.net/TZ_GG/article/details/82591191