I have a Go program that executes ffmpeg
and ffprobe
commands, so I need to install them in my Docker container.
Here is my Dockerfile:
FROM golang:1.17.7-alpine
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o ./server cmd/service/main.go
RUN apk update
RUN apk upgrade
RUN apk add --no-cache ffmpeg
FROM alpine
COPY --from=0 /src/server /usr/bin/server
CMD ["server"]
However, when I run container, it says:
exec: "ffprobe": executable file not found in $PATH
How can I fix it?
2
Answers
Because ffmpeg is a runtime dependency, not a build tool, you have to add it in the
FROM alpine
section, not theFROM golang:1.17.7-alpine
section, such that it’s installed on the image that your server is actually run in, not the system image that your server is compiled against.The smallest change to your original code that makes it work, then, would just consist of moving lines around, without needing to change anything further:
Just refactor you Dockerfile as bellow: