skip to Main Content

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


  1. Because ffmpeg is a runtime dependency, not a build tool, you have to add it in the FROM alpine section, not the FROM 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:

    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
    
    FROM alpine
    RUN apk update
    RUN apk upgrade
    RUN apk add --no-cache ffmpeg
    COPY --from=0 /src/server /usr/bin/server
    CMD ["server"]
    
    Login or Signup to reply.
  2. Just refactor you Dockerfile as bellow:

    FROM golang:1.17.7-alpine AS builder
    
    WORKDIR /src
    COPY . .
    RUN go mod tidy
    
    RUN go build -o ./server cmd/service/main.go
    
    FROM alpine
    RUN apk update && apk add --no-cache ffmpeg
    COPY --from=builder /src/server /usr/bin/server
    CMD ["server"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search