免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 33962 | 回复: 0
打印 上一主题 下一主题

Nginx Dockerfile [复制链接]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-07-23 11:11 |只看该作者 |倒序浏览
许久没在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工具.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP