- 论坛徽章:
- 1
|
许久没在CU发贴了..最近在搞docker...就发个nginx的Dockerfile吧- ############################################################
- # Dockerfile to build Nginx Installed Containers
- # Based on Offical Centos7.2
- ############################################################
- # Set the base image to Centos
- FROM centos
- # Author / Maintainer
- MAINTAINER chenqh@inno-view.com
- # Set locale
- ENV LANG en_US.UTF-8
- #Adjust timezone
- RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
- # Create user/group
- RUN groupadd -r nginx && useradd -s /sbin/nologin -g nginx -r nginx
- # Install depended package
- RUN yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel wget iproute socat
- # Install Nginx via source
- # set work home
- WORKDIR /root/
- # Get Nginx
- RUN wget -c http://nginx.org/download/nginx-1.11.1.tar.gz
- # Configure & install
- RUN tar -xzf nginx-1.11.1.tar.gz && \
- cd nginx-1.11.1 && \
- ./configure --prefix=/usr/local/nginx \
- --user=nginx \
- --group=nginx \
- --with-pcre \
- --with-stream \
- --with-stream_ssl_module \
- --with-http_ssl_module \
- --with-http_stub_status_module \
- --with-http_realip_module \
- --with-http_addition_module \
- --with-http_gzip_static_module \
- --pid-path=/var/run/nginx.pid \
- --error-log-path=/var/log/nginx/error.log \
- --http-log-path=/var/log/nginx/access.log && \
- make && make install && \
- ln -s /usr/local/nginx/conf /etc/nginx
- # Create systemd script(可以不需要,systemd脚本在centos的dokcer里存在bug:dbus error)
- #RUN echo -e 'Description=The nginx HTTP and reverse proxy server\nAfter=syslog.target network.target remote-fs.target nss-lookup.target\n\n[Service]\nType=forking\nPIDFile=/run/nginx.pid\nExecStartPre=/usr/local/nginx/sbin/nginx -t\nExecStart=/usr/local/nginx/sbin/nginx\nExecReload=/bin/kill -s HUP $MAINPID\nExecStop=/bin/kill -s QUIT $MAINPID\nPrivateTmp=true\n\n[Install]\nWantedBy=multi-user.target' > /usr/lib/systemd/system/nginx.service
- #------------------------------------------------------------------------------------------------------------------------------
- # Install Nginx via yum
- # Add application repository URL to the default sources
- # RUN echo -e '[nginx]\nname=nginx repo\nbaseurl=http://nginx.org/packages/centos/7/$basearch/\ngpgcheck=0\nenabled=1' > /etc/yum.repos.d/nginx.repo
- #
- # Install Nginx
- #RUN yum install -y nginx
- #
- # Remove the default Nginx configuration file
- #RUN rm -v /etc/nginx/nginx.conf
- #
- # Copy a configuration file from the current directory
- #ADD nginx.conf /etc/nginx/
- #--------------------------------------------------------------------------------------------------------------------------------
- # Config nginx PATH
- RUN echo 'export PATH=$PATH:/usr/local/nginx/sbin' >> /etc/profile
- ENV PATH $PATH:/usr/local/nginx/sbin
- # Append "daemon off;" to the beginning of the configuration
- RUN echo "daemon off;" >> /etc/nginx/nginx.conf
- # Expose ports
- EXPOSE 80 443
- # Set the default command to execute
- # when creating a new container
- ENTRYPOINT /usr/local/nginx/sbin/nginx
- # Start nginx in foreground
- CMD "-g daemon off;"
复制代码 再docker build -t nginx .就会自动生成nginx的docker 镜像了.
wget nginx源码包那里也可以直接使用ADD指定,可以免装wget工具. |
|