A Dockerfile installing NGINX, nginx-rtmp-module and FFmpeg from source with default settings for HLS live streaming. Built on Alpine Linux.
- Nginx 1.21.0 (Mainline version compiled from source)
- nginx-rtmp-module 1.2.2 (compiled from source)
- ffmpeg 4.4 (compiled from source)
- Default HLS settings (See: nginx.conf)
- Pull docker image and run:
docker pull pwcong/nginx-rtmp
docker run -it -p 1935:1935 -p 8080:80 --rm pwcong/nginx-rtmp
or
- Build and run container from source:
docker build -t nginx-rtmp .
docker run -it -p 1935:1935 -p 8080:80 --rm nginx-rtmp
- Stream live content to:
rtmp://localhost:1935/live/$STREAM_NAME
To enable SSL, see nginx.conf and uncomment the lines:
listen 443 ssl;
ssl_certificate /www/certs/example.com.crt;
ssl_certificate_key /www/certs/example.com.key;
This will enable HTTPS using a self-signed certificate supplied in /certs. If you wish to use HTTPS, it is highly recommended to obtain your own certificates and update the ssl_certificate and ssl_certificate_key paths.
I recommend using Certbot from Let's Encrypt.
This Docker image uses envsubst for environment variable substitution. You can define additional environment variables in nginx.conf as ${var} and pass them in your docker-compose file or docker command.
If you wish to use your own nginx.conf, mount it as a volume in your docker-compose or docker command as nginx.conf.template:
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf.template- Stream Type:
Custom Streaming Server - URL:
rtmp://localhost:1935/live - Stream Key:
hello
- Load up the example HLS player in your browser:
http://localhost:8080/player_hls.html?url=http://localhost:8080/live/hello.m3u8
- Load up the example DASH player in your browser:
http://localhost:8080/player_dash.html?url=http://localhost:8080/dash/hello.mpd
- Or in Safari, VLC or any HLS player, open:
http://localhost:8080/live/$STREAM_NAME.m3u8
- Example Playlist:
http://localhost:8080/live/hello.m3u8 - HLS.js Player
- FFplay:
ffplay -fflags nobuffer rtmp://localhost:1935/live/hello