Copy Local FFmpeg Static Build into Alpine Docker
This article provides a straightforward guide on how to copy a locally compiled, static FFmpeg binary into a clean Alpine Linux Docker container. You will learn how to structure your Dockerfile, handle permissions, and verify that the static binary runs correctly within Alpine’s lightweight environment.
Why a Static Build is Required
Alpine Linux uses musl-libc instead of the standard
glibc library found in Linux distributions like Ubuntu or
Debian. Because of this, dynamically linked binaries compiled on other
systems will not run on Alpine. A static build of FFmpeg contains all
its dependencies bundled inside the single binary, making it fully
portable and compatible with Alpine.
Step 1: Prepare Your Directory
Place your static FFmpeg binary in the same directory as your
Dockerfile. Your project structure should look like
this:
.
├── Dockerfile
└── ffmpeg
Step 2: Write the Dockerfile
Use the COPY instruction in your Dockerfile
to move the local static binary into the container’s executable path,
such as /usr/local/bin/.
FROM alpine:latest
# Install basic dependencies if needed (e.g., ca-certificates for HTTPS streaming)
RUN apk add --no-cache ca-certificates
# Copy the local static FFmpeg binary into the container
COPY ffmpeg /usr/local/bin/ffmpeg
# Grant execution permissions to the binary
RUN chmod +x /usr/local/bin/ffmpeg
# Set the default entrypoint to verify the installation
ENTRYPOINT ["ffmpeg"]Step 3: Build and Run the Container
Open your terminal, navigate to the directory containing your files, and build the Docker image:
docker build -t alpine-ffmpeg .Once the build is complete, verify that FFmpeg works correctly inside the container by running:
docker run --rm alpine-ffmpeg -versionThis command will output the version details of your static FFmpeg build, confirming that the binary is successfully integrated and operational inside your clean Alpine container.