Chinaunix

标题: Nginx Dockerfile [打印本页]

作者: 非凡公子    时间: 2016-07-23 11:11
标题: Nginx Dockerfile
许久没在CU发贴了..最近在搞docker...就发个nginx的Dockerfile吧
  1. ############################################################
  2. # Dockerfile to build Nginx Installed Containers
  3. # Based on Offical Centos7.2
  4. ############################################################

  5. # Set the base image to Centos
  6. FROM centos

  7. # Author / Maintainer
  8. MAINTAINER chenqh@inno-view.com

  9. # Set locale
  10. ENV LANG en_US.UTF-8

  11. #Adjust timezone
  12. RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

  13. # Create user/group
  14. RUN groupadd -r nginx && useradd -s /sbin/nologin -g nginx -r nginx

  15. # Install depended package
  16. RUN yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel wget iproute socat

  17. # Install Nginx via source
  18. # set work home
  19. WORKDIR /root/

  20. # Get Nginx
  21. RUN wget -c http://nginx.org/download/nginx-1.11.1.tar.gz

  22. # Configure & install
  23. RUN tar -xzf nginx-1.11.1.tar.gz && \
  24. cd nginx-1.11.1 && \
  25. ./configure --prefix=/usr/local/nginx \
  26. --user=nginx \
  27. --group=nginx \
  28. --with-pcre \
  29. --with-stream \
  30. --with-stream_ssl_module \
  31. --with-http_ssl_module \
  32. --with-http_stub_status_module \
  33. --with-http_realip_module \
  34. --with-http_addition_module \
  35. --with-http_gzip_static_module \
  36. --pid-path=/var/run/nginx.pid \
  37. --error-log-path=/var/log/nginx/error.log \
  38. --http-log-path=/var/log/nginx/access.log && \
  39. make && make install && \
  40. ln -s /usr/local/nginx/conf /etc/nginx

  41. # Create systemd script(可以不需要,systemd脚本在centos的dokcer里存在bug:dbus error)
  42. #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

  43. #------------------------------------------------------------------------------------------------------------------------------
  44. # Install Nginx via yum
  45. # Add application repository URL to the default sources
  46. # 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
  47. #
  48. # Install Nginx
  49. #RUN yum install -y nginx
  50. #
  51. # Remove the default Nginx configuration file
  52. #RUN rm -v /etc/nginx/nginx.conf
  53. #
  54. # Copy a configuration file from the current directory
  55. #ADD nginx.conf /etc/nginx/
  56. #--------------------------------------------------------------------------------------------------------------------------------

  57. # Config nginx PATH
  58. RUN echo 'export PATH=$PATH:/usr/local/nginx/sbin' >> /etc/profile
  59. ENV PATH $PATH:/usr/local/nginx/sbin

  60. # Append "daemon off;" to the beginning of the configuration
  61. RUN echo "daemon off;" >> /etc/nginx/nginx.conf

  62. # Expose ports
  63. EXPOSE 80 443

  64. # Set the default command to execute
  65. # when creating a new container
  66. ENTRYPOINT /usr/local/nginx/sbin/nginx

  67. # Start nginx in foreground  
  68. CMD "-g daemon off;"
复制代码
再docker build -t nginx .就会自动生成nginx的docker 镜像了.

wget nginx源码包那里也可以直接使用ADD指定,可以免装wget工具.




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2