Skip to content

Commit

Permalink
Reduce Docker image size (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Garfield96 authored Feb 25, 2022
1 parent 5331db5 commit 691cca9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 41 deletions.
45 changes: 27 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ ARG FFMPEG_VERSION=5.0
FROM alpine:3.15.0 as build-nginx
ARG NGINX_VERSION
ARG NGINX_RTMP_VERSION
ARG MAKEFLAGS="-j4"

# Build dependencies.
RUN apk add --update \
RUN apk add --no-cache \
build-base \
ca-certificates \
curl \
Expand All @@ -27,19 +28,21 @@ RUN apk add --update \
pkgconfig \
zlib-dev

WORKDIR /tmp

# Get nginx source.
RUN cd /tmp && \
wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
RUN wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
tar zxf nginx-${NGINX_VERSION}.tar.gz && \
rm nginx-${NGINX_VERSION}.tar.gz

# Get nginx-rtmp module.
RUN cd /tmp && \
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
RUN 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

# Compile nginx with nginx-rtmp module.
RUN cd /tmp/nginx-${NGINX_VERSION} && \
WORKDIR /tmp/nginx-${NGINX_VERSION}
RUN \
./configure \
--prefix=/usr/local/nginx \
--add-module=/tmp/nginx-rtmp-module-${NGINX_RTMP_VERSION} \
Expand All @@ -50,7 +53,8 @@ RUN cd /tmp/nginx-${NGINX_VERSION} && \
--with-debug \
--with-http_stub_status_module \
--with-cc-opt="-Wimplicit-fallthrough=0" && \
cd /tmp/nginx-${NGINX_VERSION} && make && make install
make && \
make install

###############################
# Build the FFmpeg-build image.
Expand All @@ -60,7 +64,7 @@ ARG PREFIX=/usr/local
ARG MAKEFLAGS="-j4"

# FFmpeg build dependencies.
RUN apk add --update \
RUN apk add --no-cache \
build-base \
coreutils \
freetype-dev \
Expand All @@ -83,15 +87,18 @@ RUN apk add --update \
yasm

RUN echo http://dl-cdn.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories
RUN apk add --update fdk-aac-dev
RUN apk add --no-cache fdk-aac-dev

WORKDIR /tmp

# Get FFmpeg source.
RUN cd /tmp/ && \
wget http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz && \
tar zxf ffmpeg-${FFMPEG_VERSION}.tar.gz && rm ffmpeg-${FFMPEG_VERSION}.tar.gz
RUN wget http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz && \
tar zxf ffmpeg-${FFMPEG_VERSION}.tar.gz && \
rm ffmpeg-${FFMPEG_VERSION}.tar.gz

# Compile ffmpeg.
RUN cd /tmp/ffmpeg-${FFMPEG_VERSION} && \
WORKDIR /tmp/ffmpeg-${FFMPEG_VERSION}
RUN \
./configure \
--prefix=${PREFIX} \
--enable-version3 \
Expand All @@ -115,7 +122,9 @@ RUN cd /tmp/ffmpeg-${FFMPEG_VERSION} && \
--disable-doc \
--disable-ffplay \
--extra-libs="-lpthread -lm" && \
make && make install && make distclean
make && \
make install && \
make distclean

# Cleanup.
RUN rm -rf /var/cache/* /tmp/*
Expand All @@ -130,7 +139,7 @@ ENV HTTP_PORT 80
ENV HTTPS_PORT 443
ENV RTMP_PORT 1935

RUN apk add --update \
RUN apk add --no-cache \
ca-certificates \
gettext \
openssl \
Expand All @@ -155,9 +164,9 @@ COPY --from=build-ffmpeg /usr/lib/libfdk-aac.so.2 /usr/lib/libfdk-aac.so.2

# Add NGINX path, config and static files.
ENV PATH "${PATH}:/usr/local/nginx/sbin"
ADD nginx.conf /etc/nginx/nginx.conf.template
COPY nginx.conf /etc/nginx/nginx.conf.template
RUN mkdir -p /opt/data && mkdir /www
ADD static /www/static
COPY static /www/static

EXPOSE 1935
EXPOSE 80
Expand Down
60 changes: 37 additions & 23 deletions Dockerfile.cuda
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ ARG FFMPEG_VERSION=5.0
FROM ubuntu:18.04 as build-nginx
ARG NGINX_VERSION
ARG NGINX_RTMP_VERSION
ARG MAKEFLAGS="-j4"

# Build dependencies.
RUN apt update && apt install -y \
RUN apt update && apt install -y --no-install-recommends\
build-essential \
cmake \
ca-certificates \
Expand All @@ -24,21 +25,24 @@ RUN apt update && apt install -y \
libpcre3-dev \
pkg-config \
zlib1g-dev \
wget
wget && \
rm -rf /var/lib/apt/lists/*

WORKDIR /tmp

# Get nginx source.
RUN cd /tmp && \
wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
RUN wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
tar zxf nginx-${NGINX_VERSION}.tar.gz && \
rm nginx-${NGINX_VERSION}.tar.gz

# Get nginx-rtmp module.
RUN cd /tmp && \
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
RUN 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

# Compile nginx with nginx-rtmp module.
RUN cd /tmp/nginx-${NGINX_VERSION} && \
WORKDIR /tmp/nginx-${NGINX_VERSION}
RUN \
./configure \
--prefix=/usr/local/nginx \
--add-module=/tmp/nginx-rtmp-module-${NGINX_RTMP_VERSION} \
Expand All @@ -49,7 +53,8 @@ RUN cd /tmp/nginx-${NGINX_VERSION} && \
--with-debug \
--with-http_stub_status_module \
--with-cc-opt="-Wimplicit-fallthrough=0" && \
cd /tmp/nginx-${NGINX_VERSION} && make && make install
make && \
make install

###############################
# Build the FFmpeg-build image.
Expand All @@ -61,7 +66,7 @@ ARG PREFIX=/usr/local
ARG MAKEFLAGS="-j4"

# FFmpeg build dependencies.
RUN apt update && apt install -y \
RUN apt update && apt install -y --no-install-recommends \
build-essential \
coreutils \
cmake \
Expand All @@ -88,19 +93,25 @@ RUN apt update && apt install -y \
pkg-config \
wget \
yasm \
git
git \
ca-certificates && \
rm -rf /var/lib/apt/lists/*

WORKDIR /tmp

# Clone and install ffnvcodec
RUN cd /tmp && git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git && \
cd nv-codec-headers && make install
RUN git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git && \
cd nv-codec-headers && \
make install

# Get FFmpeg source.
RUN cd /tmp/ && \
wget http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz && \
tar zxf ffmpeg-${FFMPEG_VERSION}.tar.gz && rm ffmpeg-${FFMPEG_VERSION}.tar.gz
RUN wget http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz && \
tar zxf ffmpeg-${FFMPEG_VERSION}.tar.gz && \
rm ffmpeg-${FFMPEG_VERSION}.tar.gz

# Compile ffmpeg.
RUN cd /tmp/ffmpeg-${FFMPEG_VERSION} && \
WORKDIR /tmp/ffmpeg-${FFMPEG_VERSION}
RUN \
./configure \
--prefix=${PREFIX} \
--enable-version3 \
Expand All @@ -120,7 +131,9 @@ RUN cd /tmp/ffmpeg-${FFMPEG_VERSION} && \
--extra-cflags=-I/usr/local/cuda/include \
--extra-ldflags=-L/usr/local/cuda/lib64 \
--extra-libs="-lpthread -lm" && \
make && make install && make distclean
make && \
make install && \
make distclean

# Cleanup.
RUN rm -rf /var/cache/* /tmp/*
Expand Down Expand Up @@ -154,7 +167,8 @@ RUN apt update && apt install -y --no-install-recommends \
libnvidia-encode-${NVIDIA_DRIVER_VERSION} \
libtheora0 \
openssl \
rtmpdump
rtmpdump && \
rm -rf /var/lib/apt/lists/*

COPY --from=build-nginx /usr/local/nginx /usr/local/nginx
COPY --from=build-nginx /etc/nginx /etc/nginx
Expand All @@ -164,12 +178,12 @@ COPY --from=build-ffmpeg /usr/lib/x86_64-linux-gnu/libfdk-aac.so.1 /usr/lib/x86_
# Add NGINX path, config and static files.
ENV PATH "${PATH}:/usr/local/nginx/sbin"
RUN mkdir -p /opt/data && mkdir /www
ADD nginx-cuda.conf /etc/nginx/nginx.conf.template
ADD entrypoint.cuda.sh /opt/entrypoint.sh
COPY nginx-cuda.conf /etc/nginx/nginx.conf.template
COPY entrypoint.cuda.sh /opt/entrypoint.sh
RUN chmod gu+x /opt/entrypoint.sh
ADD static /www/static
COPY static /www/static

EXPOSE 1935
EXPOSE 80

CMD /opt/entrypoint.sh
ENTRYPOINT ["/opt/entrypoint.sh"]

0 comments on commit 691cca9

Please sign in to comment.