How to download YouTube videos using Docker on Linux

I recently found a 2 hour YouTube video where I wanted to listen to the audio only.  On trying to install youtube-dl on my server, I was shocked to see the number of packages that it was trying to install.

I run Ubuntu, but this should work in any Linux distro.  Using a docker container saves polluting your server with a lot of dependencies you might not need.

If you don’t already have it, install docker:

# curl -fsSL get.docker.com -o get-docker.sh
# sh ./get-docker.sh

The following will download a video to the current working directory:

# docker run --rm  -v $PWD:/downloads wernight/youtube-dl "https://www.youtube.com/watch?v=id-here

This will extract just the audio and give you the output as an mp3:

# docker run --rm  -v $PWD:/downloads wernight/youtube-dl --extract-audio --audio-format mp3  "https://www.youtube.com/watch?v=id-here"

Leave a Reply

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.