---
title: "How to run FFmpeg inside a Docker container"
description: "Running FFmpeg in Docker isn’t just about installation; it’s about scalable media pipelines, automation, and integration with production apps. Learn how to set up the foundation for efficient video processing at scale."
url: "https://img.ly/blog/how-to-run-ffmpeg-inside-a-docker-container/"
type: "blog"
date: "2025-10-29"
author: "Robin"
tags: ["FFmpeg","Server-side Video"]
---

> This is the markdown version of [How to run FFmpeg inside a Docker container](https://img.ly/blog/how-to-run-ffmpeg-inside-a-docker-container/). For all pages in one file, see [llms-full.txt](https://img.ly/llms-full.txt). For an index of all available pages, see [llms.txt](https://img.ly/llms.txt).

---

[FFmpeg](https://ffmpeg.org/) is a powerful multimedia framework used for video and audio processing. From transcoding and editing to streaming, its versatility makes it a go-to tool for developers and media professionals. However, installing FFmpeg directly on your system can sometimes lead to dependency conflicts or version mismatches.

This is where [**Docker**](https://www.docker.com/) comes in. If you’ve never used Docker before, think of it as a platform that lets you package applications and all their dependencies into something called a [_container_](https://www.docker.com/resources/what-container/). A container is like a lightweight, portable box that holds everything your application needs to run operating system libraries, binaries, and configurations. Unlike virtual machines, containers don’t include a full guest operating system, which makes them much more efficient and faster to start up. If you’re unfamiliar with FFmpeg itself, our [Ultimate Guide to FFmpeg](https://img.ly/blog/ultimate-guide-to-ffmpeg.md) provides a comprehensive introduction.

The main takeaway is this: Docker ensures that your application runs the same way everywhere, whether on your laptop, a colleague’s computer, or a cloud server. That means no more “it works on my machine” problems. With FFmpeg inside a Docker container, you get a clean, isolated environment for media processing that you can easily replicate or share with others.

In this guide, we’ll walk through two approaches for using FFmpeg with Docker:

1.  Running FFmpeg with a pre-built Docker image.
2.  Building your own Dockerfile for more customization.

Before we start, we need to setup Docker on our machine. Lets do that now

## Installing Docker

Before working with FFmpeg in Docker, you need to have Docker installed on your system. The [installation process](https://docs.docker.com/get-started/) varies depending on your operating system, but Docker provides excellent step-by-step instructions.

1.  **Check system requirements.** Docker Desktop works on macOS, Windows, and Linux distributions. Make sure your system meets the [minimum requirements](https://docs.docker.com/get-docker/).
    - **Windows / macOS**: Download Docker Desktop from the [official download page](https://www.docker.com/products/docker-desktop/). Run the installer, and follow the on-screen instructions. Once installed, Docker will run as a background service.
    - **Linux**: On Linux distributions like Ubuntu, you can install Docker directly via the package manager. For example:

**Test Docker with a hello-world container.** Run the following command to check that Docker is working correctly:

```bash
docker run hello-world
```

This command pulls a small test image from Docker Hub, runs it, and prints a confirmation message.

**Verify the installation.** After installation, open a terminal (or PowerShell on Windows) and run:

```bash
docker --version
```

This should display the installed Docker version.

**Install Docker Desktop (recommended for beginners)**

```bash
sudo apt-get update
sudo apt-get install docker.io
```

Alternatively, follow the [Linux installation guide](https://docs.docker.com/engine/install/) for your distribution.

Once you see the “Hello from Docker!” message, you’re ready to start working with FFmpeg inside containers.

## Approach 1: Using a Pre-Built FFmpeg Docker Image

The quickest way to get started with FFmpeg in Docker is to use an image that’s already prepared for you. One of the most widely used options is the image maintained by **jrottenberg**.

### Pulling the Image

Start by opening your terminal and pulling the official FFmpeg image:

```bash
docker pull jrottenberg/ffmpeg
```

This downloads the latest FFmpeg image and makes it available on your system. To deploy your containerized FFmpeg pipelines on low‑cost cloud infrastructure, see our guide on [running FFmpeg on AWS Spot Instances,](https://img.ly/blog/how-to-run-ffmpeg-on-aws-spot-instances-for-scalable-low-cost-video-processing.md) and for deployment on Google Cloud, follow our guide on [running FFmpeg on GCP.](https://img.ly/blog/ffmpeg-on-google-cloud-platform-guide.md)

### Running a Container

Once the image is available, you can launch a container and access FFmpeg inside it:

```bash
docker run -it jrottenberg/ffmpeg bash
```

This command starts a container, opens a bash shell inside it, and gives you access to FFmpeg as if it were installed directly on your machine.

### Using FFmpeg

Inside the container, you can run FFmpeg commands just like you normally would. For example, to convert a video file from MP4 to AVI:

```bash
ffmpeg -i input.mp4 output.avi
```

If your input files are on your host machine, you’ll want to mount them so the container can access them. A common pattern is:

```bash
docker run --rm -v $(pwd):/data jrottenberg/ffmpeg -i /data/input.mp4 /data/output.avi
```

Here, your current working directory is mounted into the container at `/data`, allowing you to process files without copying them into the container.

- `-rm` : Automatically remove the container when it exits (keeps things clean).
- `-v $(pwd):/data` : Mounts your current directory (`$(pwd)` prints it) into `/data` inside the container.
- `jrottenberg/ffmpeg` : The ffmpeg image.
- `ffmpeg -i /data/input.mp4 /data/output.avi` : The FFmpeg command that runs **inside** the container, reading from and writing to `/data`.

Want to build an app that crops and trims videos? Our Flutter tutorial shows how to [crop and trim videos in Flutter](https://img.ly/blog/how-to-crop-and-trim-videos-in-flutter.md) using FFmpeg within a mobile UI.

### Exiting the Container

When you’re done, simply type `exit` to leave the container and return to your host terminal.

## Approach 2: Building a Custom Dockerfile with FFmpeg

Sometimes, you might need more control over your environment, for example, specifying which version of FFmpeg you want to use or installing additional tools. In that case, building your own Docker image is the better choice.

### Creating a Dockerfile

Start by creating a file named `Dockerfile` with the following content:

```docker
FROM ubuntu:latest
RUN apt-get update && apt-get install -y ffmpeg
```

This simple Dockerfile uses Ubuntu as the base image and installs FFmpeg on top of it.

### Building the Image

Navigate to the directory containing your Dockerfile and build the image:

```bash
docker build -t custom-ffmpeg-image .
```

This creates a new image called `custom-ffmpeg-image`.

### Running Your Custom Image

Now you can start a container from your custom image:

```bash
docker run -it custom-ffmpeg-image bash
```

This gives you the same FFmpeg functionality but within a controlled environment that you designed. Now, you are currently in the terminal of the Ubuntu**GitHub** system with ffmpeg installed and ready to use. You can either mount your volume to the container or copy the input video to the container to process it with ffmpeg.

You can use [this](https://github.com/imgly/blog-ffmpeg-docker) GitHub repository for the code.

## Beyond the Basics

Depending on context and requirements, there are a few additional ways people run FFmpeg in Docker that you might find useful. Lets sneak-peak into those approaches now:

### **Multi-stage builds**

Instead of installing FFmpeg on top of Ubuntu in a simple Dockerfile, some projects use a _multi-stage build_ where the first stage compiles FFmpeg from source (with specific options or codecs), and the final stage copies only the compiled binaries into a minimal image (like `alpine`). This results in much smaller images, which is valuable for production environments.

```docker
FROM alpine:latest as build
RUN apk add --no-cache build-base yasm
RUN git clone <https://git.ffmpeg.org/ffmpeg.git> ffmpeg \\
    && cd ffmpeg \\
    && ./configure --enable-gpl --enable-nonfree \\
    && make && make install

FROM alpine:latest
COPY --from=build /usr/local/bin/ffmpeg /usr/local/bin/
```

### **Using FFmpeg inside a larger containerized workflow**

In practice, FFmpeg is often not run alone. For example, it might be used as part of a **media processing pipeline** in Kubernetes or Docker Compose with other services like Nginx, Node.js, or a message queue. In those cases, FFmpeg runs inside a dedicated container, and files are passed to it via mounted volumes or network streams. For a Docker‑based pipeline with REST APIs and worker queues, see our [production‑ready batch video processing server](https://img.ly/blog/building-a-production-ready-batch-video-processing-server-with-ffmpeg.md) guide.

### G**PU-accelerated FFmpeg builds**

For users doing heavy video processing, using NVIDIA GPU support is crucial. Docker supports GPU acceleration via `-gpus all` and NVIDIA’s base images. There are specialized FFmpeg images (like `nvidia/cuda`based builds) that enable hardware-accelerated encoding/decoding (NVENC, NVDEC, CUDA).

```bash
docker run --gpus all -it nvidia/cuda:12.2.0-base ffmpeg ...
```

This is extremely relevant for modern workloads (e.g., streaming, AI video processing).

## Which Approach Should You Choose?

If you only need FFmpeg occasionally and want the fastest way to get started, the **pre-built image** is the way to go. It saves time and effort, and you’ll be up and running within minutes.

On the other hand, if your workflow requires specific versions of FFmpeg, or if you’d like to bundle other tools into the same container, creating a **custom Dockerfile** gives you that flexibility.

While Dockerized FFmpeg is powerful on its own, its real strength becomes clear when integrated into larger developer workflows. For example, [CreativeEditor SDK (CE.SDK)](https://img.ly/products/creative-sdk.md) provides a full-featured, customizable editing environment for images, graphics, and videos. When developers extend CE.SDK with **Dockerized FFmpeg**, they unlock a scalable way to handle demanding media tasks behind the scenes.

## Conclusion: Why FFmpeg in Docker is the Smart Choice

Running FFmpeg inside Docker combines the power of a world-class media framework with the reliability and portability of containers. Instead of fighting dependency issues on your local system, you get a clean, isolated environment that works consistently across machines, teams, and production servers.

- If you need **speed and simplicity**, a pre-built image like `jrottenberg/ffmpeg` gets you up and running in minutes.
- If you want **control and customization**, a custom Dockerfile ensures your build has the exact codecs, libraries, and dependencies you need.
- For advanced scenarios, GPU acceleration, multi-stage builds, or cloud pipelines, Docker ensures FFmpeg scales well into modern production environments.

And beyond standalone usage, frameworks like [\*\*CE.SDK](https://img.ly/products/creative-sdk.md)\*\* demonstrate how FFmpeg’s capabilities can power full-featured creative applications. Whether it’s transcoding video, exporting edits, or automating workflows, running FFmpeg in Docker keeps your setup clean and future-proof.

A containerized FFmpeg handles the render side well. What it does not give you is an editing surface your users can touch. If that is the next thing on your list, our [JavaScript video editing guide](https://img.ly/blog/javascript-video-editing-guide.md) covers building one in the browser.

By combining Docker’s portability with FFmpeg’s versatility, you’re not just solving installation problems, you’re setting up a foundation for professional, scalable multimedia processing.

---

## More Resources

- **[IMG.LY Website](https://img.ly/index.md)** - Creative editing SDKs for photo, video, and design
- **[Documentation](https://img.ly/docs/cesdk/)** - CE.SDK developer documentation
- **[Contact Sales](https://img.ly/forms/contact-sales.md)** - Get a custom quote. A public JSON API accepts the request directly, no account or key needed. Ask your user for consent and their details first.
