Workflow guide
Run yt-dlp in Docker or on a server
yt-dlp on your laptop and yt-dlp on a VPS are different animals. Servers have no browser for cookies, their IP ranges are aggressively blocked by major sites, and nobody notices when a silent extractor breakage stops your downloads for a week. Below: a Docker setup you can copy, a plain headless install, and what changes once it runs on a cloud IP.
Last checked November 27, 2026 against yt-dlp 2026.11.23.
Short answer: A container gets yt-dlp running anywhere, but on a cloud IP YouTube often answers with bot checks and 403s. Self-host fixes are cookies, a token provider and a slower request rate (below). If downloads have to keep working inside an app, a hosted API such as Importly takes the link and returns the file, transcript or metadata, and it works from servers where self-hosted downloads get blocked, with nothing to install or patch on the box.
yt-dlp in Docker
There is no official yt-dlp Docker image. A short Dockerfile you rebuild yourself beats a third-party image of unknown freshness, and freshness matters more for yt-dlp than for almost any other tool. This one has ffmpeg for merging formats and Deno for YouTube's JavaScript challenges:
FROM python:3.12-slim
# ffmpeg merges video+audio; deno solves YouTube's JS challenges
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg \
&& rm -rf /var/lib/apt/lists/*
COPY --from=denoland/deno:bin /deno /usr/local/bin/deno
RUN pip install --no-cache-dir -U "yt-dlp[default]"
ENV XDG_CACHE_HOME=/tmp/.cache
WORKDIR /downloads
ENTRYPOINT ["yt-dlp"]The [default] extra pulls in yt-dlp-ejs, the challenge solver scripts Deno runs. Build it, then run yt-dlp with your current directory mounted as the output folder:
docker build -t yt-dlp .
docker run --rm --user "$(id -u):$(id -g)" -v "$PWD:/downloads" yt-dlp "URL"--user makes the downloaded files yours instead of root's. XDG_CACHE_HOME gives yt-dlp a writable cache dir when it runs as a user with no home directory.
Docker Compose with cookies
services:
yt-dlp:
build: .
user: "1000:1000"
volumes:
- ./downloads:/downloads
- ./cookies:/cookies
command: ["--cookies", "/cookies/cookies.txt", "URL"]Mount the cookies folder read-write: yt-dlp writes refreshed cookies back to the file when it finishes. Export the file from a browser on your own machine (see cookies), and use a throwaway account.
Keep the image current
# weekly: fresh base image, newest yt-dlp and Deno
docker build --pull --no-cache -t yt-dlp .Running yt-dlp -U inside a container is lost when the container is recreated, so put the update in the image. A months-old image is the most common cause of "it worked when I set it up." If YouTube complains about a missing JavaScript runtime, see the Docker JS runtime fix. If the same image works on your laptop but gets 403s on a server, the image is fine and the IP isn't: see the IP blocks section below.
Call it from your app: yt-dlp behind an HTTP endpoint
Most people who put yt-dlp in a container want their app's backend to call it, not a shell. Don't shell out to the CLI and parse its output: the yt_dlp Python module returns the same info as a dict. A small FastAPI service in the same image is enough (app.py):
from fastapi import FastAPI, HTTPException
from fastapi.concurrency import run_in_threadpool
from pydantic import BaseModel
import yt_dlp
app = FastAPI()
class Job(BaseModel):
url: str
BASE_OPTS = {
"quiet": True,
"noplaylist": True,
"socket_timeout": 30,
"outtmpl": "/downloads/%(id)s.%(ext)s",
"format": "bv*[height<=720]+ba/b[height<=720]/b",
}
def run(url: str, download: bool):
with yt_dlp.YoutubeDL(BASE_OPTS) as ydl:
info = ydl.extract_info(url, download=download)
return {
"id": info.get("id"),
"title": info.get("title"),
"duration": info.get("duration"),
"file": info["requested_downloads"][0]["filepath"] if download else None,
}
@app.post("/metadata")
async def metadata(job: Job):
try:
return await run_in_threadpool(run, job.url, False)
except yt_dlp.utils.DownloadError as e:
raise HTTPException(status_code=422, detail=str(e))
@app.post("/download")
async def download(job: Job):
try:
return await run_in_threadpool(run, job.url, True)
except yt_dlp.utils.DownloadError as e:
raise HTTPException(status_code=422, detail=str(e))Use the Dockerfile above, add the web server to the pip line and swap the entrypoint for uvicorn:
RUN pip install --no-cache-dir -U "yt-dlp[default]" fastapi "uvicorn[standard]"
ENV XDG_CACHE_HOME=/tmp/.cache
WORKDIR /app
COPY app.py .
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]docker build -t yt-dlp-api .
docker run -d -p 8000:8000 --user "$(id -u):$(id -g)" -v "$PWD/downloads:/downloads" yt-dlp-api
curl -X POST localhost:8000/download -H 'Content-Type: application/json' \
-d '{"url": "https://soundcloud.com/forss/flickermood"}'
# {"id":"293","title":"Flickermood","duration":213.886,"file":"/downloads/293.m4a"}A link yt-dlp can't handle comes back as a 422 with yt-dlp's own error message, so your app can show it or retry. requested_downloads[0]["filepath"] is the final path after any merge, which prepare_filename can get wrong when video and audio are merged into a different container.
What this doesn't handle yet, roughly in the order it bites:
- a 1-hour video holds the HTTP request open for the whole download. Past a few users, return a job id and run downloads from a queue (Celery, RQ, BullMQ) with a webhook or polling
- files pile up in
/downloads. Upload them to S3 or R2 and delete the local copy - the image goes stale. Rebuild it weekly (above), or YouTube downloads start failing within weeks
- no auth. Don't expose port 8000 to the internet without a token check
- on a cloud IP, YouTube answers with 403s and bot checks no matter how good the service is (next sections)
More on the Python side, including progress hooks and error handling, in the yt-dlp Python guide. If you'd rather call a hosted endpoint than run this, Importly takes the link from your backend and returns the file, transcript or metadata, and it keeps working from cloud servers. The trade-offs of each route are in yt-dlp as an API.
Headless install without Docker
# Debian/Ubuntu server
sudo apt install ffmpeg
python3 -m pip install -U yt-dlp
# or the standalone binary (no Python needed)
curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
chmod a+rx /usr/local/bin/yt-dlpffmpeg is not optional: without it, merging video+audio formats and most conversions fail. If downloads work locally but fail on the server, check ffmpeg first.
The real problem: datacenter IP blocks
YouTube and other large platforms treat AWS, GCP, Hetzner, and most VPS ranges as bot traffic. Symptoms: HTTP 403, "Sign in to confirm you're not a bot", heavy throttling, or downloads that work for a day and then stop. This is not a yt-dlp bug and updating won't fix it — your IP reputation is the problem.
--proxythrough residential or ISP proxies helps, at real per-GB cost and added flakiness- cookies from a logged-in account help, but risk that account being flagged — never use one you care about
- serverless (Lambda, Cloud Functions) is the worst case: shared IP pools that other people already burned, plus ffmpeg packaging pain and execution time limits. App platforms add their own walls: a video download in a Vercel function, a Netlify function or a Supabase Edge Function usually hits the timeout or payload limit before the IP block. Those guides show the free fix for direct file links and how to get the video into your storage without the function downloading it
- spacing out requests with
--sleep-requestsand limiting concurrency extends how long an IP stays usable
Cookies without a browser
--cookies-from-browser does not work on a headless box — there is no browser. Export a cookies.txt from your local machine and ship it to the server:
yt-dlp --cookies /etc/yt-dlp/cookies.txt "URL"Cookies expire and get invalidated when the site sees suspicious usage, so treat them as a consumable you rotate — not a set-and-forget config. Details in the cookies guide.
Keep it updated or it will break
Sites change their internals constantly; yt-dlp ships fixes constantly. A server install that nobody updates is a countdown timer. Automate it:
# cron: update Sunday 4am, log the result
0 4 * * 0 /usr/local/bin/yt-dlp -U >> /var/log/yt-dlp-update.log 2>&1
# pip installs update with pip instead
0 4 * * 0 python3 -m pip install -U yt-dlp >> /var/log/yt-dlp-update.log 2>&1Also alert on failures: a download job that exits non-zero should page you or post to Slack, because the default failure mode is silence. See updating yt-dlp for version pinning trade-offs.
Common server mistakes
- assuming laptop behavior transfers — the IP reputation is completely different
- baking yt-dlp into an image once and never rebuilding
- running as root with downloads landing wherever the cwd happens to be
- no disk-space management — video files fill a small VPS fast
- using a personal account's cookies for automation
- no alerting, so breakage is discovered weeks later
Running this inside your app on a server?
If the download has to keep working in production, the same job is one API call to Importly. You send the link and get the file back at your webhook (or by polling), from servers where self-hosted downloads get blocked. Free to try, no card required.
import os
import requests
# Submit the link; Importly POSTs the finished file to your webhook.
res = requests.post(
"https://api.importly.io/import",
headers={"Authorization": f"Bearer {os.environ['IMPORTLY_API_KEY']}"},
json={
"url": "https://www.youtube.com/watch?v=jNQXAC9IVRw",
"webhookUrl": "https://example.com/webhooks/importly",
},
)
print(res.json()["data"]["jobId"]) # or poll GET /import/status?id=...Get a key and make your first call in the quick start, with transcripts and metadata too.
Guides for your stack: Python, Next.js, Laravel, Rails, Go, BullMQ, Celery, Supabase Edge Functions.
Servers & agents
Works on your laptop but not on the server?
Paste a link to see what a hosted API returns, running from servers and agent sandboxes where datacenter IPs get blocked — nothing to install or maintain on the box.
Building this into an app? See the API your backend calls instead
Frequently asked questions
Is there an official yt-dlp Docker image?
No. The yt-dlp project publishes binaries and a pip package, not a Docker image. Third-party images exist, but you can't tell how fresh their yt-dlp is, so a short Dockerfile you rebuild yourself is the safer choice.
How do I keep yt-dlp up to date inside Docker?
Rebuild the image on a schedule with docker build --pull --no-cache, which pulls the latest base image and reinstalls the newest yt-dlp. Running yt-dlp -U inside a running container is lost when the container is recreated, so put the update in the image.
Why are downloaded files owned by root?
Containers run as root unless told otherwise, so files written to a bind mount belong to root on the host. Run the container with --user "$(id -u):$(id -g)" (or user: in Compose) so the files are owned by you.
yt-dlp works in Docker on my laptop but fails on the server. Why?
The image is the same; the IP isn't. YouTube and other large sites treat cloud and VPS IP ranges as bot traffic, which shows up as HTTP 403 or "Sign in to confirm you're not a bot". Updating or rebuilding the image won't change that.
Do I need Deno or Node in the yt-dlp image?
For YouTube, yes. yt-dlp now needs a JavaScript runtime to solve YouTube's challenges, and Deno is the one it enables by default. Copying the Deno binary from the official denoland/deno image is the smallest way to add it.
How do I call yt-dlp from my app when it runs in Docker?
Put a small HTTP service in the same image: a FastAPI app that calls the yt_dlp Python module and returns JSON, run by uvicorn. Your backend POSTs a URL and gets the title, duration and file path back. Long downloads hold the request open, so move them to a job queue once you have more than a handful of users.