Skip to the content.

Tutorial: Running OpenAI Whisper in Docker

This tutorial shows how to build a Docker image for OpenAI Whisper and use it to transcribe audio files on your machine. You don’t need to install Python, Whisper, or FFmpeg locally because everything runs inside the container.

The setup uses two files:


1. Prerequisites

Check your installation:

docker --version
docker compose version

2. Project layout

Create the following structure:

openai-whisper-docker/
├── Dockerfile
├── docker-compose.yml
├── audio-files/      # put your audio files here; transcripts are written here too
└── models/           # downloaded Whisper models are cached here
mkdir -p openai-whisper-docker/audio-files openai-whisper-docker/models
cd openai-whisper-docker

3. Create the Dockerfile

Create a file named Dockerfile with this content:

FROM ubuntu:22.04

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
    sudo \
    python3.9 \
    python3-distutils \
    python3-pip \
    ffmpeg \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade pip

RUN pip install -U openai-whisper


FROM scratch

COPY --from=0 / /

WORKDIR /app

CMD ["whisper"]

What it does

Step Purpose
FROM ubuntu:22.04 Uses Ubuntu 22.04 as the base.
apt-get install ... Installs Python, pip, and FFmpeg, which Whisper uses to decode audio formats such as mp3, m4a, and wav.
apt-get clean && rm -rf /var/lib/apt/lists/* Removes the apt cache to make the image smaller.
pip install -U openai-whisper Installs Whisper and its dependencies, including PyTorch.
FROM scratch + COPY --from=0 / / Copies the first stage’s filesystem into an empty image, which squashes all layers into one.
WORKDIR /app Sets /app as the working directory, where your audio files are mounted.
CMD ["whisper"] Runs the whisper CLI by default.

4. Create the docker-compose.yml

Create a file named docker-compose.yml with this content:

services:
  whisper:
    build:
      context: .
      dockerfile: Dockerfile
    platform: linux/arm64
    working_dir: /app
    command: ["whisper"]
    volumes:
      - ./models:/root/.cache/whisper
      - ./audio-files:/app
    stdin_open: true
    tty: true

What it does

Key Purpose
build Builds the image from the Dockerfile in the current directory.
platform: linux/arm64 Builds and runs for ARM64 (for example, Apple Silicon Macs). On an Intel/AMD machine, change this to linux/amd64 or remove the line.
working_dir: /app Runs commands in /app.
command: ["whisper"] Sets the default command. You can override it on the command line.
./models:/root/.cache/whisper Saves downloaded models on your host so they are downloaded only once.
./audio-files:/app Makes your local audio files available in the container and saves the transcripts back to your host.
stdin_open / tty Keeps an interactive terminal open so you can see progress output.

5. Build the image

docker compose build

Compose names the image <project-folder>-<service>. If the folder is named openai-whisper-docker, the image is named openai-whisper-docker-whisper.

Option B: Plain Docker

docker build --platform linux/arm64 -t openai-whisper-docker-whisper .

Check that the image was created:

docker images | grep whisper

The first build can take several minutes because PyTorch is a large download.


6. Transcribe an audio file

  1. Copy an audio file into audio-files/, for example audio-files/meeting.m4a.
  2. Run Whisper with one of the following options.

Option A: Docker Compose

docker compose run --rm whisper \
    whisper meeting.m4a \
    --model turbo \
    --output_dir /app \
    --output_format txt

Option B: Plain Docker

docker run --rm -it \
    --platform linux/arm64 \
    -v "${PWD}/models:/root/.cache/whisper" \
    -v "${PWD}/audio-files:/app" \
    openai-whisper-docker-whisper \
    whisper meeting.m4a \
    --model turbo \
    --output_dir /app \
    --output_format txt

When it finishes, the transcript is in audio-files/meeting.txt.

The first run downloads the selected model into models/. Later runs use the cached copy.

Specify the language

Whisper detects the language automatically, but setting it is faster and often more accurate:

docker compose run --rm whisper \
    whisper Azkar.mp3 \
    --model turbo \
    --language Arabic \
    --output_dir /app \
    --output_format txt

Translate to English

docker compose run --rm whisper \
    whisper meeting.m4a --model turbo --task translate --output_dir /app

7. Useful Whisper options

Option Description Example
--model Model size: tiny, base, small, medium, large-v3, turbo --model turbo
--language Spoken language; skips auto-detection --language English
--task transcribe (default) or translate (to English) --task translate
--output_dir Where to write results; use /app to save them to audio-files/ --output_dir /app
--output_format txt, srt, vtt, tsv, json, or all --output_format srt
--device cpu or cuda; CUDA requires an NVIDIA GPU --device cpu

See all options:

docker compose run --rm whisper whisper --help

Choosing a model

Model Speed Accuracy Approx. memory
tiny / base Fastest Lowest ~1 GB
small Fast Good ~2 GB
medium Slow Better ~5 GB
turbo Fast Close to large-v3 ~6 GB
large-v3 Slowest Best ~10 GB

turbo is a good default for most uses.


8. Optional: helper script

To avoid typing the full command each time, create run.sh:

#!/bin/bash
# Usage: ./run.sh <audio-file> [extra whisper args...]
FILE="$1"; shift

DOCKER_DEFAULT_PLATFORM=linux/arm64 docker run --rm -it \
    -v "${PWD}/models:/root/.cache/whisper" \
    -v "${PWD}/audio-files:/app" \
    openai-whisper-docker-whisper \
    whisper "$FILE" \
    --model turbo \
    --output_dir /app \
    --output_format txt \
    "$@"
chmod +x run.sh
./run.sh meeting.m4a
./run.sh Azkar.mp3 --language Arabic

9. Troubleshooting

Problem Fix
exec format error or a platform mismatch warning The platform value doesn’t match your CPU. Use linux/amd64 on Intel/AMD and linux/arm64 on Apple Silicon/ARM.
No such file or directory for the audio file Make sure the file is in audio-files/ and pass only the file name, not a host path.
The process is killed or runs out of memory Use a smaller model (small or base), or increase Docker Desktop’s memory limit under Settings → Resources.
Every run downloads the model again Check that the ./models:/root/.cache/whisper volume is mounted.
Processing is very slow The container uses the CPU, especially on macOS, where Docker cannot use the Apple GPU. Use a smaller model or set --language.

10. Cleanup

docker compose down --rmi local     # remove the built image
rm -rf models/*                     # delete cached models

References