Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a docker image with nginx compile options for Optional HTTP modules

I am trying to build an nginx image for installing nginx with the Module ngx_http_auth_request_module.

this is my current docker file:

#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

typically i would have compiled the nginx files locally like this:

sudo ./configure --with-http_auth_request_module

and then install nginx

sudo make install

but how can i do this with docker file?

please help

like image 486
lobengula3rd Avatar asked Mar 04 '15 19:03

lobengula3rd


People also ask

Where is nginx config in Docker?

By default, Nginx looks in the /usr/share/nginx/html directory inside of the container for files to serve. We need to get our html files into this directory. A fairly simple way to do this is use a mounted volume.

What is nginx image in Docker?

Nginx (pronounced "engine-x") is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and a web server (origin server). The nginx project started with a strong focus on high concurrency, high performance and low memory usage.


1 Answers

I'm somewhat of a noob with Docker, but I had to solve this same problem. I used this Dockerfile as a starting point.

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;"]
like image 123
max Avatar answered Sep 25 '22 02:09

max