Dockerfile构建nginx
1.安装nginx的shell脚本
#!/bin/bash yum install -y gcc gcc-c++ make pcre pcre-devel zlib zlib-devel cd /usr/local/nginx-1.16.0 ./configure --prefix=/usr/local/nginx && make && make install
2.dockerfile
FROM centos:7
ADD nginx-1.16.0.tar.gz /usr/local
COPY nginx_install.sh /usr/local
RUN sh /usr/local/nginx_install.sh
EXPOSE 80
3.制作Nginx镜像:
docker build -t mycentos:nginx .
4.Nginx镜像启动注意
在容器里nginx是以daemon方式启动,退出容器时,nginx程序也会随着停止: /usr/local/nginx/sbin/nginx
使用前台方式永久运行:/usr/local/nginx/sbin/nginx -g "daemon off;"
5.检查验证:
docker run -itd -p 999:80 mycentos:nginx /usr/local/nginx/sbin/nginx -g "daemon off;"
FROM centos:7 ADD nginx-1.16.0.tar.gz /usr/local COPY nginx_install.sh /usr/local RUN sh /usr/local/nginx_install.sh EXPOSE 80