Live stream to YouTube with your Raspberry Pi and Docker

In this guide we'll set up our Raspberry Pi so that we can stream live video to YouTube to either a public, unlisted or private stream.

Using a pre-built Docker image means we know exactly what we're getting and instead of having to go through lots of manual steps we can type in a handful of commands and get started immediately.


The YouTube live dashboard show my Raspberry Pi cluster and Pimoroni LED blinkt! boards.

Acknowledgements: thanks to Richard Gee for giving me the idea to live stream with a Raspberry Pi.

The old way of doing things

Normally this would have involved typing in many manual CLI commands and waiting up to 9 hours for some video encoding software (ffmpeg) to compile itself. If you got anything wrong you'd have to add on another 9 hours of compilation time (on a PiZero). In fact while compiling this tutorial I left my Pi running over night and it ran out of disk space meaning I had to start all over again.

The guide

You'll need a Raspberry Pi, I've used a Pi Zero here and the accompanying camera cable. Once you've setup the camera according to the official guide you're going to be good to go.

Also enable SSH via raspi-config and login remotely so you can save yourself some typing.

This guide work with Raspbian Jessie Lite as well as the full Pixel desktop.

Step 1. Install Docker

Installing Docker on the Pi is a one-line script:

$ curl -sSL | sh

$ sudo usermod pi -aG docker

$ reboot

Step 2. Test the camera

To make sure your camera is plugged in properly fire off a test shot. This will also help us gauge whether the orientation is correct:

$ sudo raspistill -o tester.jpg

You can then use scp or sftp to copy the file back to your Mac, Linux or Windows machine.

As a Windows user you may want to install Git bash which provides all the common UNIX-like utilities used with a Linux system.

Step 3. Pull the image down

The Docker image I produced took almost 9 hours to build, so you have two options now - either rebuild it yourself (over 9 hours) or pull it down from the Docker Hub. It's a 640MB download which will expand to 1.3GB in disk space:

$ docker pull alexellis2/streaming:17-5-2017

Step 4. Get your secret streaming key

Now head over to your Youtube live streaming dashboard. Make sure you've filled in all the details and click Reveal to see your key:

Now copy and paste your key (i.e. xxxx-xxxx-xxxx-xxxx( into the Raspberry Pi's terminal like this:

$ docker run --privileged --name cam -ti alexellis2/streaming:17-5-2017 xxxx-xxxx-xxxx-xxxx

You'll now be streaming live to the Internet, so pick wisely whether you want to keep that stream private, unlisted or public.

To cancel the stream just hit Control + C or shutdown the Pi.

This is me doing some late night testing for the blog.

Share your URL!

You can now share your URL with your audience and check out your statistics in real-time. There may be a delay of a few seconds - this is entirely normal and you can tweak lots of settings on the dashboard.

Step 5. Tweaks

Running in the background

To run in the background just swap out the -ti flag for -d:

$ docker run --privileged --name cam -d alexellis2/streaming:17-5-2017 xxxx-xxxx-xxxx-xxxx

Run on boot-up

To automatically stream every time you power up, then just add the flag --restart=always to the docker run command line.

Add effects to the video

This is a more advanced step, but you can add effects to change the colour or rotate the picture by editing the file in the provided Github repository.


By default the command-line we used won't be transmitting audio, for that we'd have to recompile ffmpeg using the Dockerfile and some additional options.

In our script we set an empty audio channel since YouTube requires us to stream some audio, even if it's empty.

Positioning your camera

If you'd like to set your camera up on a window then there are two products I'd recommend which come with mini suction cups.

At the budget end you have the ZeroView from ThePiHut and at the premium end you have the cute Octocam kit from Pimoroni which contains all the hardware necessary for the project.

Now I want to learn Docker!

If you'd like to learn more about Docker on the Raspberry Pi then head over to my free tutorial series as featured in Docker Weekly.

There you'll be able to Build a Timelapse Rig with your Raspberry Pi, Create an Environmental Monitoring Dashboard, get started right at the beginning with a video and much more!

Follow me on Twitter for all the latest blogs and tutorials

Alex Ellis

Read more posts by this author.

United Kingdom

Subscribe to alex ellis' blog

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!