Copy FFmpeg Static Build into Alpine Docker Container
This guide explains how to transfer a locally compiled, static FFmpeg binary into a minimal Alpine Linux Docker container. By using a truly static build, you can bypass dependency conflicts between your host C library (such as glibc) and Alpine's musl libc. You will learn the correct project directory structure, the minimal Dockerfile instructions required to copy and set permissions for the binary, and how to verify the installation inside the container.
Step 1: Verify the Local Static Binary
Before copying the binary, ensure it is completely statically linked. If it relies on dynamic libraries from your host system, it will fail to execute inside Alpine.
Run the file command on your local binary:
file ./ffmpegThe output must indicate statically linked. For example:
ffmpeg: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked
Step 2: Prepare the Directory Structure
Place your static ffmpeg binary (and
ffprobe, if needed) in the same directory as your
Dockerfile:
project-directory/
├── Dockerfile
└── ffmpeg
Step 3: Create the Dockerfile
Use the COPY instruction to transfer the binary into
standard system execution paths like /usr/local/bin/. Set
appropriate execution permissions within the image.
Create a Dockerfile with the following contents:
FROM alpine:latest
# Copy the static binary to the system PATH
COPY ffmpeg /usr/local/bin/ffmpeg
# Ensure the binary has execute permissions
RUN chmod +x /usr/local/bin/ffmpeg
# Set the entrypoint to the ffmpeg command
ENTRYPOINT ["ffmpeg"]
CMD ["-version"]Step 4: Build and Verify the Container
Build the Docker image using the docker build
command:
docker build -t alpine-ffmpeg .Once the build finishes, verify that the binary executes correctly inside Alpine:
docker run --rm alpine-ffmpeg -versionIf the static build was linked properly, FFmpeg will print its
version and configuration details without requiring any additional
runtime libraries installed via apk.