# Run yt-dlp in Docker or on a server

Run yt-dlp in Docker or headless on a VPS: a tested Dockerfile with ffmpeg and Deno, a small HTTP API your app can call, cookies, rebuilding so it stays current, and why it fails on cloud IPs.

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.

<HostedAnswer>
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).
</HostedAnswer>

## 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:

```dockerfile
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:

```bash
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

```yaml
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](/guides/yt-dlp-cookies)), and use a throwaway account.

### Keep the image current

```bash
# 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](/guides/yt-dlp-docker-js-runtime). 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`):

```python
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:

```dockerfile
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"]
```

```bash
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](/guides/yt-dlp-python). If you'd rather call a hosted endpoint than run this, [Importly](https://www.importly.io/?utm_source=ytdlp.org&utm_medium=referral&utm_campaign=doc-cta&utm_content=server-http-api&utm_term=%2Fguides%2Frun-yt-dlp-server) 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](/guides/yt-dlp-api).

## Headless install without Docker

```bash
# 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-dlp
```

ffmpeg 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](/guides/fix-ffmpeg-not-found).

## 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.

- `--proxy` through 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](https://www.importly.io/docs/integrations/vercel-function-limits?utm_source=ytdlp.org&utm_medium=referral&utm_campaign=doc-cta&utm_content=serverless-limits&utm_term=%2Fguides%2Frun-yt-dlp-server), a [Netlify function](https://www.importly.io/docs/integrations/netlify-function-limits?utm_source=ytdlp.org&utm_medium=referral&utm_campaign=doc-cta&utm_content=serverless-limits&utm_term=%2Fguides%2Frun-yt-dlp-server) or a [Supabase Edge Function](https://www.importly.io/docs/integrations/supabase-edge-function-limits?utm_source=ytdlp.org&utm_medium=referral&utm_campaign=doc-cta&utm_content=serverless-limits&utm_term=%2Fguides%2Frun-yt-dlp-server) 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-requests` and 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:

```bash
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](/guides/yt-dlp-cookies).

## 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:

```bash
# 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>&1
```

Also 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](/guides/update-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

<AppCodeTabs />

<DocCta variant="server-agent" />

<Faq />

## Related guides

- [Use yt-dlp as an API](/guides/yt-dlp-api)
- [Use yt-dlp in Python](/guides/yt-dlp-python)
- [Automate yt-dlp: cron, n8n, Zapier](/guides/yt-dlp-automation)
- [Use cookies with yt-dlp](/guides/yt-dlp-cookies)
- [Use a proxy with yt-dlp](/guides/yt-dlp-proxy)
- [Run yt-dlp on AWS Lambda](/guides/yt-dlp-aws-lambda)
- [Fix common yt-dlp errors](/guides/fix-yt-dlp-errors)
- [Fix the JS runtime error in Docker](/guides/yt-dlp-docker-js-runtime)
- [Run a PO token provider as a sidecar](/guides/yt-dlp-po-token-server)