环境1:
- 系统:Linux Centos 7.4 x64
- 内核:Linux docker 3.10.0-693.2.2.el7.x86_64
- Docker 版本:18.09.1
- redis 版本:nginx-1.15.7
- 主机数量:1台
- 主机地址:192.168.1.81
环境2:
- 已搭建 Docker Swarm 管理
- 已搭建 Docker 私有仓库
- 已搭建 NFS 存储
目录结构
├── nginx
│ ├── dist.zip # 自定义项目
│ ├── Dockerfile
│ ├── nginx-1.15.7.tar.gz
│ ├── nginx.conf
│ ├── openssl-1.1.1a.tar.gz
│ ├── pcre-8.42.tar.gz
│ ├── vhosts.conf
│ └── zlib-1.2.11.tar.gz
└── service_nginx.yml
下载
- nginx压缩包
- 下载地址:https://pan.baidu.com/s/1yb783fGyn62kWi8j3hvtmQ
- 密码:h41v
- openssl压缩包
- 下载地址:https://pan.baidu.com/s/1l5oiq0-ZzRP00oTfEd6aqA
- 密码:8uk3
- pcre压缩包
- 下载地址:https://pan.baidu.com/s/1sXDtYsRlye1ANwCz3bS8BA
- 密码:mrmd
- zlib压缩包
- 下载地址:https://pan.baidu.com/s/1AWsZ00uhn32KCg9eGSF1SA
- 密码:6mwr
1、创建dockerfile
FROM centos:6 MAINTAINER xiangsikai ENV LANG en_US.UTF-8 ENV TZ=Asia/Shanghai RUN yum install sudo unzip -y RUN sudo yum update -y && \ sudo yum groupinstall -y 'Development Tools' && \ sudo yum install -y epel-release && \ sudo yum install -y perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel GeoIP GeoIP-devel ADD nginx-1.15.7.tar.gz /home/root/ ADD pcre-8.42.tar.gz /home/root/ ADD zlib-1.2.11.tar.gz /home/root/ ADD openssl-1.1.1a.tar.gz /home/root/ RUN cd /home/root/nginx-1.15.7/ && ./configure --prefix=/usr/local/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --user=nginx \ --group=nginx \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-select_module \ --with-poll_module \ --with-threads \ --with-file-aio \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_xslt_module=dynamic \ --with-http_image_filter_module=dynamic \ --with-http_geoip_module=dynamic \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_auth_request_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_degradation_module \ --with-http_slice_module \ --with-http_stub_status_module \ --with-mail=dynamic \ --with-mail_ssl_module \ --with-stream=dynamic \ --with-stream_ssl_module \ --with-stream_realip_module \ --with-stream_geoip_module=dynamic \ --with-stream_ssl_preread_module \ --with-compat \ --with-pcre=../pcre-8.42 \ --with-pcre-jit \ --with-zlib=../zlib-1.2.11 \ --with-openssl=../openssl-1.1.1a \ --with-openssl-opt=no-nextprotoneg \ --with-debug && \ make && make install RUN sudo useradd nginx && sudo mkdir /etc/nginx/conf.d COPY nginx.conf /etc/nginx/nginx.conf COPY vhosts.conf /etc/nginx/conf.d/ ADD dist.zip /usr/local/nginx/html/ RUN unzip /usr/local/nginx/html/dist.zip -d /usr/local/nginx/html/ CMD ["nginx","-g","daemon off;"] EXPOSE 80
# 指定系统镜像版本 FROM centos:6 # 指定管理员名称 MAINTAINER xiangsikai # 添加变量,指定中文编码 ENV LANG en_US.UTF-8 # 添加变量,同步系统时间 ENV TZ=Asia/Shanghai # 添加命令 RUN yum install sudo unzip -y # 添加命令 RUN sudo yum update -y && \ sudo yum groupinstall -y 'Development Tools' && \ sudo yum install -y epel-release && \ sudo yum install -y perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel GeoIP GeoIP-devel # 添加文件 ADD nginx-1.15.7.tar.gz /home/root/ # 添加文件 ADD pcre-8.42.tar.gz /home/root/ # 添加文件 ADD zlib-1.2.11.tar.gz /home/root/ # 添加文件 ADD openssl-1.1.1a.tar.gz /home/root/ # 添加命令 RUN cd /home/root/nginx-1.15.7/ && ./configure --prefix=/usr/local/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --user=nginx \ --group=nginx \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-select_module \ --with-poll_module \ --with-threads \ --with-file-aio \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_xslt_module=dynamic \ --with-http_image_filter_module=dynamic \ --with-http_geoip_module=dynamic \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_auth_request_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_degradation_module \ --with-http_slice_module \ --with-http_stub_status_module \ --with-mail=dynamic \ --with-mail_ssl_module \ --with-stream=dynamic \ --with-stream_ssl_module \ --with-stream_realip_module \ --with-stream_geoip_module=dynamic \ --with-stream_ssl_preread_module \ --with-compat \ --with-pcre=../pcre-8.42 \ --with-pcre-jit \ --with-zlib=../zlib-1.2.11 \ --with-openssl=../openssl-1.1.1a \ --with-openssl-opt=no-nextprotoneg \ --with-debug && \ make && make install # 添加命令 RUN sudo useradd nginx && sudo mkdir /etc/nginx/conf.d # 添加文件 COPY nginx.conf /etc/nginx/nginx.conf # 添加文件 COPY vhosts.conf /etc/nginx/conf.d/ # 添加文件 ADD dist.zip /usr/local/nginx/html/ # 添加命令 RUN unzip /usr/local/nginx/html/dist.zip -d /usr/local/nginx/html/ # 启动命令 CMD ["nginx","-g","daemon off;"] # 开放端口 EXPOSE 80