docker-nginx


1.Dockerfile_nginx

# This nginx Dockerfile
# Version 20240206

# Base images 基础镜像
FROM dockerstorage.xxx.com:5533/os/anolisos:latest

#ENV 设置环境变量
ENV PATH=/usr/local/nginx/sbin:$PATH
ENV CLASSPATH=.:$CLASSPATH

#RUN 执行以下命令
RUN useradd -s /sbin/nologin -M nginx

#ADD 文件放在当前目录下,拷过去会自动解压
ADD nginx-1.24.0.tar.gz /home/
ADD openssl-1.1.1w.tar.gz /home/
ADD nginx-goodies-nginx-sticky-module-ng.tgz /home/

#WORKDIR 相当于cd
WORKDIR /home/nginx-1.24.0

#编译安装
RUN ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --http-log-path=/usr/local/nginx/logs/access.log --error-log-path=/usr/local/nginx/logs/error.log --with-file-aio --with-http_ssl_module --with-pcre --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --add-module=/home/nginx-goodies-nginx-sticky-module-ng --with-openssl=/home/openssl-1.1.1w && make && make install

#添加启动脚本
RUN echo '#!/bin/bash' >> /home/run.sh
RUN echo '/usr/local/php8/sbin/php-fpm' >> /home/run.sh
RUN echo '/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf' >> /home/run.sh
RUN chmod 775 /home/run.sh

#安装libiconv
ADD libiconv-1.17.tar.gz /home/
WORKDIR /home/libiconv-1.17
RUN ./configure && make && make install

#安装curl
ADD curl-8.6.0.tar.gz /home/
WORKDIR /home/curl-8.6.0
RUN ./configure --without-nss --with-ssl && make && make install

#安装php
ADD php-8.2.14.tar.gz /home/
WORKDIR /home/php-8.2.14
RUN ./configure --prefix=/usr/local/php8 --with-config-file-path=/usr/local/php8/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-shared --enable-debug --enable-soap --enable-bcmath --enable-calendar --enable-dom --enable-exif --enable-fileinfo --enable-filter --enable-ftp --enable-gd-jis-conv --enable-mbstring --enable-mbregex --enable-pdo --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mysqlnd-compression-support --enable-gd --enable-opcache --enable-xml --with-sqlite3 --with-iconv --with-bz2 --with-curl --with-cdb --with-openssl --with-jpeg --with-freetype --with-xpm --with-gettext --with-mhash --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --with-zlib-dir --with-pdo-sqlite --with-readline --with-xsl --with-pear --with-gmp --with-iconv=/usr/local && make ZEND_EXTRA_LIBS='-liconv' && make install
RUN ./libtool --finish /usr/local/php8/lib/
ADD php.ini /usr/local/php8/etc/
ADD php-fpm.conf /usr/local/php8/etc/
ADD www.conf /usr/local/php8/etc/php-fpm.d/
ADD nginx.conf /usr/local/nginx/conf/
ADD index.php /usr/local/nginx/html/

#CMD 运行以下命令
CMD /home/run.sh && tail -f /dev/null

2.docker-compose.yml

# 编排服务(容器),每个服务启动一个镜像
# Time: 20240206
version: '3'

services:
nginx:
restart: always
# env_file:
# - .env
image: dockerstorage.xxx.com:5533/nginx/nginx-base:latest
container_name: nginx-base
build:
context: ./
dockerfile: Dockerfile_nginx
ports:
- "8181:80"
# volumes:
# - ./logs:/usr/local/nginx/logs
environment:
- utf8
- TZ=Asia/Shanghai
extra_hosts:
- "dockermysql.xxx.com:host-gateway"
dns:
- 114.114.114.114
- 223.5.5.5
- 8.8.8.8
networks:
- basic
ulimits:
nproc:
soft: 65535
hard: 65535
nofile:
soft: 65535
hard: 65535

networks:
basic:
driver: bridge