我正在尝试使用Module ngx_http_auth_request_module构建一个用于安装nginx的nginx映像。
这是我当前的泊坞文件:
#ubuntu OS
FROM ubuntu:14.04
#update apt-get non interactive and install nginx
RUN \
sudo apt-get -q -y update; \
sudo apt-get -q -y install nginx
#copy all mapping configurations for all environments
COPY ./resources/routing-configs/* /routing-configs/
#expose port for nginx
EXPOSE 80
#run task to copy only relevant mapping configuration to nginx and reload nginx service
COPY ./resources/start.sh /opt/mysite/router/start.sh
RUN sudo chmod 766 /opt/mysite/router/start.sh
CMD sudo -E sh /opt/mysite/router/start.sh
通常我会在本地编译nginx文件,如下所示:
sudo ./configure --with-http_auth_request_module
然后安装nginx
sudo make install
但是如何使用docker文件执行此操作?
请帮助
答案 0 :(得分:3)
我有点像Docker的菜鸟,但我不得不解决同样的问题。我用这个Dockerfile作为起点。
FROM centos:centos7
WORKDIR /tmp
# Install prerequisites for Nginx compile
RUN yum install -y \
wget \
tar \
openssl-devel \
gcc \
gcc-c++ \
make \
zlib-devel \
pcre-devel \
gd-devel \
krb5-devel \
openldap-devel \
git
# Download Nginx and Nginx modules source
RUN wget http://nginx.org/download/nginx-1.9.3.tar.gz -O nginx.tar.gz && \
mkdir /tmp/nginx && \
tar -xzvf nginx.tar.gz -C /tmp/nginx --strip-components=1 &&\
git clone https://github.com/kvspb/nginx-auth-ldap.git /tmp/nginx/nginx-auth-ldap
# Build Nginx
WORKDIR /tmp/nginx
RUN ./configure \
--user=nginx \
--with-debug \
--group=nginx \
--prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/run/nginx.pid \
--lock-path=/run/lock/subsys/nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_spdy_module \
--with-pcre \
--with-http_image_filter_module \
--with-file-aio \
--with-ipv6 \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--add-module=nginx-auth-ldap && \
make && \
make install
WORKDIR /tmp
# Add nginx user
RUN adduser -c "Nginx user" nginx && \
setcap cap_net_bind_service=ep /usr/sbin/nginx
RUN touch /run/nginx.pid
RUN chown nginx:nginx /etc/nginx /etc/nginx/nginx.conf /var/log/nginx /usr/share/nginx /run/nginx.pid
# Cleanup after Nginx build
RUN yum remove -y \
wget \
tar \
gcc \
gcc-c++ \
make \
git && \
yum autoremove -y && \
rm -rf /tmp/*
# PORTS
EXPOSE 80
EXPOSE 443
USER nginx
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]