| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- FROM arm64v8/alpine:3.18 AS build-nginx
- ARG NGINX_VERSION=1.23.1
- ARG NGINX_RTMP_VERSION=1.2.2
- ARG MAKEFLAGS="-j4"
- # 构建依赖
- RUN apk add --no-cache \
- build-base \
- ca-certificates \
- curl \
- gcc \
- libc-dev \
- libgcc \
- linux-headers \
- make \
- musl-dev \
- openssl \
- openssl-dev \
- pcre \
- pcre-dev \
- pkgconf \
- pkgconfig \
- zlib-dev
- # 编译nginx和rtmp模块
- WORKDIR /tmp
- RUN wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
- tar zxf nginx-${NGINX_VERSION}.tar.gz && \
- rm nginx-${NGINX_VERSION}.tar.gz && \
- wget https://github.com/arut/nginx-rtmp-module/archive/v${NGINX_RTMP_VERSION}.tar.gz && \
- tar zxf v${NGINX_RTMP_VERSION}.tar.gz && \
- rm v${NGINX_RTMP_VERSION}.tar.gz
- WORKDIR /tmp/nginx-${NGINX_VERSION}
- RUN ./configure \
- --prefix=/usr/local/nginx \
- --add-module=/tmp/nginx-rtmp-module-${NGINX_RTMP_VERSION} \
- --conf-path=/etc/nginx/nginx.conf \
- --with-threads \
- --with-file-aio \
- --with-http_ssl_module \
- --with-debug \
- --with-http_stub_status_module \
- --with-cc-opt="-Wimplicit-fallthrough=0" && \
- make && \
- make install
- # 构建FFmpeg
- FROM arm64v8/alpine:3.18 AS build-ffmpeg
- ARG FFMPEG_VERSION=5.1
- ARG PREFIX=/usr/local
- ARG MAKEFLAGS="-j4"
- RUN apk add --no-cache \
- build-base \
- coreutils \
- freetype-dev \
- lame-dev \
- libogg-dev \
- libass \
- libass-dev \
- libvpx-dev \
- libvorbis-dev \
- libwebp-dev \
- libtheora-dev \
- openssl-dev \
- opus-dev \
- pkgconf \
- pkgconfig \
- rtmpdump-dev \
- wget \
- x264-dev \
- x265-dev \
- yasm
- RUN echo http://dl-cdn.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \
- apk add --no-cache fdk-aac-dev
- WORKDIR /tmp
- RUN wget http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz && \
- tar zxf ffmpeg-${FFMPEG_VERSION}.tar.gz && \
- rm ffmpeg-${FFMPEG_VERSION}.tar.gz
- WORKDIR /tmp/ffmpeg-${FFMPEG_VERSION}
- RUN ./configure \
- --prefix=${PREFIX} \
- --enable-version3 \
- --enable-gpl \
- --enable-nonfree \
- --enable-small \
- --enable-libmp3lame \
- --enable-libx264 \
- --enable-libx265 \
- --enable-libvpx \
- --enable-libtheora \
- --enable-libvorbis \
- --enable-libopus \
- --enable-libfdk-aac \
- --enable-libass \
- --enable-libwebp \
- --enable-postproc \
- --enable-libfreetype \
- --enable-openssl \
- --disable-debug \
- --disable-doc \
- --disable-ffplay \
- --extra-libs="-lpthread -lm" && \
- make && \
- make install
- # 最终镜像
- FROM arm64v8/alpine:3.18
- LABEL version="1.0" \
- description="NGINX RTMP Server ARM64" \
- maintainer="zhensolidsl"
- ENV HTTP_PORT=80 \
- HTTPS_PORT=443 \
- RTMP_PORT=1935 \
- PATH="/usr/local/bin:${PATH}:/usr/local/nginx/sbin"
- # 安装运行依赖
- RUN apk update && \
- apk add --no-cache \
- ca-certificates \
- gettext \
- openssl \
- pcre \
- lame \
- libogg \
- curl \
- libass \
- libvpx \
- libvorbis \
- libwebp \
- libtheora \
- opus \
- rtmpdump \
- x264-dev \
- x265-dev
- # 复制构建产物
- COPY --from=build-nginx /usr/local/nginx /usr/local/nginx
- COPY --from=build-nginx /etc/nginx /etc/nginx
- COPY --from=build-ffmpeg /usr/local /usr/local
- COPY --from=build-ffmpeg /usr/lib/libfdk-aac.so.2 /usr/lib/libfdk-aac.so.2
- # 复制配置文件
- COPY nginx.conf /etc/nginx/nginx.conf.template
- COPY static /www/static
- # 创建必要目录
- RUN mkdir -p /opt/data/hls /www /var/log/nginx
- # 设置权限
- RUN addgroup -S nginx && \
- adduser -S -G nginx nginx && \
- chown -R nginx:nginx /opt/data /www /usr/local/nginx /etc/nginx /var/log/nginx && \
- chmod -R 755 /opt/data
- VOLUME ["/opt/data/hls"]
- EXPOSE 1935 80
- HEALTHCHECK --interval=30s --timeout=3s \
- CMD curl -f http://localhost:${HTTP_PORT}/healthcheck || exit 1
- CMD ["sh", "-c", "envsubst \"$(env | sed -e 's/=.*//' -e 's/^/\\$/g')\" < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && nginx -g 'daemon off;'"]
|