I’m not hugely familiar with Docker and I’m trying to learn and be better at it. So here goes.

The scenario.

I have three webcams for a weather site (www.alberniweather.ca). They are currently pointing to an old iMac running Debian that takes the streams and overlays weather data. But the iMac is old and is straining.

I have a newer iMac (2014 – running macOS 13) that I have used for this task in the past, but I’d like to use Docker to run the stream to compartmentalize things and make it more portable in future to other systems.

So here goes.

I am going to try using the container nginx-rtmp example from tiangolo.

The Steps

  1. It’s hard to get Docker running on macOS without using Docker Desktop if you’ve never done it before.
  2. I used the homebrew method described here.
    • Go through the instructions there to install homebrew and docker.
    • but later realized that minikube was beyond my understanding at some point… so while I installed the packages, I ended up trying something else so:
    • Do not start minikube.
  3. I ended up using colima as there was more information about using it on a Mac to run docker.
    • brew install colima
  4. I also ended up needing to install “BuildX” as the “docker build” commands are now deprecated (and not well documented) so make sure you install docker buildx with homebrew:
    • brew install docker-buildx
  5. You must specifically tell colima to open the network interface! (This stumped me for a long time). This is a macOS-only issue due to permissions so it was hard to find the solution. I started it with colima start –network-address my.host.ip.address
  6. To Start Colima I used:
    colima start –cpu 2 –memory 4 –dns 1.1.1.1 –dns 192.168.1.254 –network-address
    • the “-network-address” command is specific for macOS based systems and is required for macOS to allow colima to use the network!
  7. First I created a folder for the Dockerfiles to live called “westimage”. It’s in ~/Docker/westimage
  8. Next I created a new file called DockerFile (westimage/Dockerfile)
    • I’m using the basic DockerFile instructions to figure this out.
    • I only have 2 lines in my DockerFile since I am only changing the nginx configuration and nothing else
    • “FROM tiangolo/nginx-rtmp
      COPY nginx.conf /etc/nginx/nginx.conf”
  9. Next I created an nginx.conf file in the same folder and copy/pasted in the example from vallahaye/nginx
  10. I modified the nginx file to use my own playpath/streaming key location for YouTube.
    • worker_processes auto;
      rtmp_auto_push on;
      events {}
      rtmp {
      server {
      listen 1935;
      listen [::]:1935 ipv6only=on;
      application west { live on; record off; push rtmp://a.rtmp.youtube.com app=live2 playpath=streamkey; } }
      }
  11. Build the custom docker image from the DockerFile that has the original rtmp image and the new nginx file.
    • “docker buildx build –tag chrisale-nginx-rtmp-yt:latest .”
    • take note of the tag, this is your way of identifying it (without that tag you would have to reference it by its numbered id reported in ‘docker images’.
    • Before the colon : is the repository
    • After the colon : is the version (use “latest”
    • also note the “.” that references the current directory as the place to look for the DockerFile
  12. You can now use “docker push” to publish the image on a cloud repository if you choose. I didn’t do this as I don’t want the public seeing my fumbling, outside this blog post anyway but if I try to deploy this on another machine then I will publish it somewhere.
  13. run the docker image!
    • docker run -d -p 1935:1935 –name rtmp-west chrisale-nginx-rtmp-yt
    • “docker run” tells docker to run an image
    • -d means it will detach and run as a background process.
    • -p 1935:1935 assigns an external and internal port so that the container will accept requests on that port.
    • — name rtmp-west specifies the name the container will run under so you can see it in ‘docker ps’
    • and chrisale-nginx-rtmp-yt is the repository and built image that you have created.
  14. If you want to look inside the container you can use these commands to get into a running container with bash, and then install nano to then see a file
    • docker exec -t -i nginx-rtmp /bin/bash
    • apt-get update
    • apt-get install nano
  15. You should now be able to point your webcam to the nginx docker image with something like:
    • rtmp:192.168.1.223:1935/west/webcam
    • “west” has to match the application you named in nginx.
    • The “webcam” portion is less important.
    • If you have multiple webcams you could create multiple docker containers from the same Dockerfile and give them different names and outside facing ports by running them with:
    • docker run -d -p 19351:1935 –name rtmp-west chrisale-nginx-rtmp-yt-west
    • docker run -d -p 19352:1935 –name rtmp-south chrisale-nginx-rtmp-yt-south
    • etc
  16. If you’re having trouble with your installation, use docker logs –follow to see the logs from your container. You can also use the exec command in step 14 to examine logs directly on the container. You may need to rebuild your docker container with nginx error logs enabled in the conf file.
  17. You should now be able to go to your Youtube Studio and start the live broadcast. If if you have confirmed with nginx debug that the docker container is receiving from the webcam but Youtube is not receiving data, try rebooting the webcam.
  18. Congratulations you should now have a functioning nginx relay for a webcam to youtube!

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Murkyview

Subscribe now to keep reading and get access to the full archive.

Continue reading