Archive

Posts Tagged ‘docker’

rtmp streaming to multiple platforms at once using nginx with docker

juni 27th, 2020 No comments

It’s been while since I posted here, and since I recently did something that is worth to put on here, I’ll have another go 😉

I’m part of the hamradio YOTA project, and with the epidemic thingie we wanted to do some live sessions on Youtube, Facebook and twitch at once.

To capture/broadcast I’m using OBS on my desktop PC, however, this software can only push to one streaming service at once, unless I open up multiple OBS’s and try to set things up that way, but that could lag your computer, and if you have bandwidth limitations, this can also create issues.

So, I wanted to push the stream to one of my datacenter servers, and transcode(where needed)/redistribute to the streaming platforms from there.
This makes it so I only have to upload once from a “home” connection
In my tests, my rtmp stream +-6 Mbit up from home, +-17 Mbit up from datacenter to the services.
Optionally people can also pull from that service, or you can distribute it to more servers for other people to look live, if you want to have your own mini rtmp setup.

Since I like to use docker, I’ve created a Dockerfile that builds nginx with this rtmp module.
I’ve also created a docker-compose so it’s easy for you to get started an try it out yourself.
(Requires some experience with servers and docker)
You can find it here:
https://github.com/Maescool/docker-nginx-rtmp

Note, if your home router overheats and restarts during the stream, cause of heatwave (yeah I need to get an airco in that tech room), you might have to stop the broadcast and start it again, cause it doesn’t handle disconnects that well.. if facebook is disconnected too long they stop and you might need to reset that stream key.. Youtube nicely waits, for twitch it doesn’t matter

73 de ON1GPS

Docker Service Discovery (aka resolv the IP’s of your running containers)

september 30th, 2015 No comments

Note: In this blogpost I expect that you are aware of docker, it’s basics and how to use it. Also, don’t blame me if this doesn’t work, cause PEBKAC

I’ve been experimenting with docker for the last year in a hobby project, which is running a small Minecraft server network for a Youtuber called Xisumavoid

docker came to my attention some time last year (2014), heard people talking and praising it, so I checked it out, I’ve been hooked ever since.

One feature of docker is a lot of fun, the –link feature, this puts the hostname of the certain container to it’s proper IP.
However, this doesn’t update when the container you linked to restarts.. which is annoying.. also your container doesn’t start when that container isn’t up.

Also, if you want to connect to the containers from your host, or another host, say through a different docker container on a different host, yeah.. issues..

What I have found to work is this combination:

It’s a strange combination, but it works for me just fine.

This is how it works:

dnsdock is connected to the docker API, using the socket, Yes there is some security related discussion that discourages this practice… but for this one app, which is open source.. and has no direct incoming connection to the outside world.. I don’t worry that much.

The powerdns part, is basically a recursive dns server, which will combine the queries for all the docker instances, powerdns is quiet the powerfull dns server.. so that way I’m sure resolving doesn’t crash that easy.

Now, how do i make all of this work, like this:


#!/bin/bash
docker pull tonistiigi/dnsdock
docker pull urelx/pdns-recursor

docker run -d -v /var/run/docker.sock:/var/run/docker.sock --name dnsdock -p 172.17.42.1:5300:53/udp tonistiigi/dnsdock -environment="servername"
docker run -d --name powerdns \
-p 172.17.42.1:53:53 -p 172.17.42.1:53:53/udp \
urelx/pdns-recursor --forward-zones="servername.docker=172.17.42.1:5300, otherservername.docker=172.17.42.2:5300" --forward-zones-recurse=".=8.8.8.8"

In this example I also added a 2nd baremetal server, with ip 172.17.42.2

I’m aware this is not the most advanced thing, and could be expanded in lots of ways, but this just a simple proof of concept that does the basics you need in order to resolv containers.
More info you’ll find on the dnsdock repo.

However, how does this basically work

the hostname looks something like this:
containername.imagename.environment.docker.

so if you run a mysql server, name mysql1 (assuming you use the official mysql image) it looks like this:
mysql1.mysql.servername.docker.

Interesting fact, if you have mysql1, mysql2, etc, you can dns loadbalance:
mysql.servername.docker. will give back all the ip’s of the running containers, using that image.