dockerfile自定义编译安装nginx镜像

安装的nginx包为nginx-1.12.2.tar.gz,可到nginx官方网站下载

dockerfile中是使用COPY把nginx源码包放入镜像中的,如使用ADD则不需要tar的步骤

FROM centos:7
ADD install_nginx.sh /nginx/install_nginx.sh
COPY nginx-1.12.2.tar.gz /nginx/
WORKDIR /nginx/
RUN bash /nginx/install_nginx.sh
EXPOSE 80
CMD ["nginx"]

dockerfile中用到了install_nginx.sh

install_nginx.sh

#!/bin/bash
nginx_package="nginx-1.12.2.tar.gz"
# 安装环境依赖
yum -y install gcc gcc-c++ make pcre* zlib-devel autoconf automake
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
# 创建运行用户、组
useradd -M -s /sbin/nologin nginx
# 编译安装
tar -xf $nginx_package
cd ${nginx_package%.tar.*}
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-stream \
--with-http_ssl_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
# 容器中没有后台进程的概念,把nginx放到前台
echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf

你可能感兴趣的:(docker,dockerfile,docker,nginx)