gpt4 book ai didi

docker - 使用可选 HTTP 模块的 nginx 编译选项创建 docker 镜像

转载 作者:行者123 更新时间:2023-12-04 20:01:43 25 4
gpt4 key购买 nike

我正在尝试使用模块 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 文件做到这一点?

请帮忙

最佳答案

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

关于docker - 使用可选 HTTP 模块的 nginx 编译选项创建 docker 镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28863126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com