Dockerfile 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. FROM registry.cn-chengdu.aliyuncs.com/reghao/debian:bullseye-slim
  2. # debian11 使用 ustc 源
  3. RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list && \
  4. sed -i 's|security.debian.org/debian-security|mirrors.ustc.edu.cn/debian-security|g' /etc/apt/sources.list
  5. # 安装编译 nginx 源码需要的依赖
  6. RUN apt clean && apt update -y && apt install -y --no-install-recommends \
  7. gcc make zlib1g zlib1g-dev openssl libssl-dev libpcre3 libpcre3-dev libgd-dev libexif-dev && \
  8. rm -rf /var/lib/apt/lists/*
  9. # 复制 nginx 和 nginx-http-flv-module 源码
  10. COPY nginx-1.18.0.tar.gz /nginx-1.18.0.tar.gz
  11. COPY v1.2.12.tar.gz /v1.2.12.tar.gz
  12. RUN tar zxf nginx-1.18.0.tar.gz && tar zxf v1.2.12.tar.gz
  13. # 创建 nginx 用户
  14. RUN useradd -M -s /sbin/nologin nginx
  15. # 切换至 nginx 源码目录
  16. WORKDIR /nginx-1.18.0
  17. # 配置编译选项, --add-module 指定了 nginx-http-flv-module 模块
  18. RUN ./configure \
  19. --prefix=/usr/local/nginx \
  20. --user=nginx \
  21. --group=nginx \
  22. --sbin-path=/usr/local/nginx/sbin/nginx \
  23. --modules-path=/usr/local/nginx/modules \
  24. --conf-path=/usr/local/nginx/conf/nginx.conf \
  25. --error-log-path=/usr/local/nginx/logs/error.log \
  26. --http-log-path=/usr/local/nginx/logs/access.log \
  27. --pid-path=/usr/local/nginx/logs/nginx.pid \
  28. --lock-path=/usr/local/nginx/logs/nginx.lock \
  29. --with-http_stub_status_module \
  30. --with-http_ssl_module \
  31. --add-module=/nginx-http-flv-module-1.2.12
  32. # 编译源码
  33. RUN make && make install
  34. # 将 nginx 日志重定向到 stdout 和 stderr, 这样可通过 docker logs 直接查看日志
  35. RUN ln -sf /dev/stdout /usr/local/nginx/logs/access.log && ln -sf /dev/stderr /usr/local/nginx/logs/error.log
  36. # 创建 rtmp 推流的 flv 文件存放位置, rtmp 的 record_path 参数中配置
  37. RUN mkdir -p /data/rtmp
  38. # 使用自定义的 nginx.conf
  39. COPY nginx.conf /usr/local/nginx/conf/nginx.conf
  40. WORKDIR /
  41. # 删除安装使用的文件和文件夹
  42. RUN rm -rf nginx-1.18.0.tar.gz
  43. RUN rm -rf nginx-1.18.0
  44. RUN rm -rf nginx-http-flv-module-1.2.12.tar.gz
  45. RUN rm -rf nginx-http-flv-module-1.2.12
  46. # nginx 默认以后台模式启动, docker 未执行到自定义的 CMD 之前 nginx 的 pid 是 1
  47. # 执行到 CMD 后 nginx 开始后台运行,bash 的 pid 变成了 1, 一旦执行完自定义 CMD,nginx 容器也就退出
  48. # 为了保证 nginx 容器不退出, 应该关闭 nginx 的后台运行
  49. CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]