forked from alfg/docker-nginx-rtmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.cuda
189 lines (166 loc) · 4.3 KB
/
Dockerfile.cuda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
ARG NGINX_VERSION=1.23.1
ARG NGINX_RTMP_VERSION=1.2.2
ARG FFMPEG_VERSION=5.1
##############################
# Build the NGINX-build image.
FROM ubuntu:22.04 as build-nginx
ARG NGINX_VERSION
ARG NGINX_RTMP_VERSION
ARG MAKEFLAGS="-j4"
# Build dependencies.
RUN apt update && apt install -y --no-install-recommends\
build-essential \
cmake \
ca-certificates \
curl \
gcc \
libc-dev \
make \
musl-dev \
openssl \
libssl-dev \
libpcre3 \
libpcre3-dev \
pkg-config \
zlib1g-dev \
wget && \
rm -rf /var/lib/apt/lists/*
WORKDIR /tmp
# Get nginx source.
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 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.
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
###############################
# Build the FFmpeg-build image.
FROM nvidia/cuda:11.7.0-devel-ubuntu20.04 as build-ffmpeg
ENV DEBIAN_FRONTEND=noninteractive
ARG FFMPEG_VERSION
ARG PREFIX=/usr/local
ARG MAKEFLAGS="-j4"
# FFmpeg build dependencies.
RUN apt update && apt install -y --no-install-recommends \
build-essential \
coreutils \
cmake \
libx264-dev \
libx265-dev \
libc6 \
libc6-dev \
libfreetype6-dev \
libfdk-aac-dev \
libmp3lame-dev \
libogg-dev \
libass9 \
libass-dev \
libnuma1 \
libnuma-dev \
libopus-dev \
librtmp-dev \
libvpx-dev \
libvorbis-dev \
libwebp-dev \
libtheora-dev \
libtool \
libssl-dev \
pkg-config \
wget \
yasm \
git \
ca-certificates && \
rm -rf /var/lib/apt/lists/*
WORKDIR /tmp
# Clone and install ffnvcodec
RUN git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git && \
cd nv-codec-headers && \
make install
# Get FFmpeg source.
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.
WORKDIR /tmp/ffmpeg-${FFMPEG_VERSION}
RUN \
./configure \
--prefix=${PREFIX} \
--enable-version3 \
--enable-gpl \
--enable-nonfree \
--enable-small \
--enable-libfdk-aac \
--enable-openssl \
--enable-libnpp \
--enable-cuda \
--enable-cuvid \
--enable-nvenc \
--enable-libnpp \
--disable-debug \
--disable-doc \
--disable-ffplay \
--extra-cflags=-I/usr/local/cuda/include \
--extra-ldflags=-L/usr/local/cuda/lib64 \
--extra-libs="-lpthread -lm" && \
make && \
make install && \
make distclean
# Cleanup.
RUN rm -rf /var/cache/* /tmp/*
##########################
# Build the release image.
FROM nvidia/cuda:11.7.0-devel-ubuntu20.04
LABEL MAINTAINER Alfred Gutierrez <alf.g.jr@gmail.com>
ENV DEBIAN_FRONTEND=noninteractive
ENV NVIDIA_DRIVER_VERSION=455
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,video,utility
# Set default ports.
ENV HTTP_PORT 80
ENV HTTPS_PORT 443
ENV RTMP_PORT 1935
# Set default options.
ENV SINGLE_STREAM ""
ENV MAX_MUXING_QUEUE_SIZE ""
ENV ANALYZEDURATION ""
RUN apt update && apt install -y --no-install-recommends \
ca-certificates \
curl \
gettext \
libpcre3-dev \
libnvidia-decode-${NVIDIA_DRIVER_VERSION} \
libnvidia-encode-${NVIDIA_DRIVER_VERSION} \
libtheora0 \
openssl \
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
COPY --from=build-ffmpeg /usr/local /usr/local
COPY --from=build-ffmpeg /usr/lib/x86_64-linux-gnu/libfdk-aac.so.1 /usr/lib/x86_64-linux-gnu/libfdk-aac.so.1
# Add NGINX path, config and static files.
ENV PATH "${PATH}:/usr/local/nginx/sbin"
RUN mkdir -p /opt/data && mkdir /www
COPY nginx-cuda.conf /etc/nginx/nginx.conf.template
COPY entrypoint.cuda.sh /opt/entrypoint.sh
RUN chmod gu+x /opt/entrypoint.sh
COPY static /www/static
EXPOSE 1935
EXPOSE 80
ENTRYPOINT ["/opt/entrypoint.sh"]