【问题标题】:creating a docker image with nginx compile options for Optional HTTP modules使用可选 HTTP 模块的 nginx 编译选项创建 docker 映像
【发布时间】:2015-03-04 19:26:21
【问题描述】:

我正在尝试使用模块 ngx_http_auth_request_module 构建一个用于安装 nginx 的 nginx 映像。

这是我当前的 docker 文件:

#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 文件来做到这一点?

请帮忙

【问题讨论】:

  • 在 Dockerfile 中使用“sudo”通常是不必要的,因为一切(默认情况下)都以 root 身份运行。
  • 是的,我知道,但这与我的问题有什么关系?
  • 这只是一般建议。至于您的问题,究竟是什么阻止您在 Dockerfile 中执行 ./configuremake

标签: docker boot2docker dockerfile


【解决方案1】:

我对 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;"]

【讨论】:

    猜你喜欢
    • 2020-12-14
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 2021-05-05
    • 2019-02-21
    • 2022-01-05
    • 1970-01-01
    • 2021-04-10
    相关资源
    最近更新 更多