Skip to content

Comments

Use Alpine and Clean Up Dockerfile#212

Open
decaffeinatedio wants to merge 2 commits intoprebid:masterfrom
decaffeinatedio:use-alpine
Open

Use Alpine and Clean Up Dockerfile#212
decaffeinatedio wants to merge 2 commits intoprebid:masterfrom
decaffeinatedio:use-alpine

Conversation

@decaffeinatedio
Copy link

@decaffeinatedio decaffeinatedio commented Dec 5, 2025

I ran a quick test to deploy Prebid Cache + Redis with Dokku on a random VPS and noticed a number of issues with the Dockerfile. I think this proposed PR will make things faster, cleaner and more secure.

FWIW, this also shrinks the (local) image size from ~129MB to ~29MB.

Major changes:

  • Switch from Ubuntu 22 to Alpine 3.23.
  • Support ARM
  • Pin Go version for more reproducible builds
  • Simplify build and strip out unwanted files with .dockerignore

@decaffeinatedio decaffeinatedio changed the title Use alpine Use Alpine and Clean Up Dockerfile Dec 5, 2025
@linux019
Copy link

I'm using a simpler dockerfile, also go vendoring is enabled to prevent modules download at the compile stage every time

ARG GOVERSION=1.25.3

FROM golang:${GOVERSION}-alpine3.22 AS builder
WORKDIR /build/
RUN apk add --no-cache pcre-dev bash gcc musl-dev git
COPY ./ ./
ARG TEST="false"
RUN if [ "$TEST" != "false" ]; then ./validate.sh ; fi
RUN go build -mod=vendor -trimpath -ldflags "\
    -X github.com/prebid/prebid-cache/version.Ver=$(git describe --tags) \
    -X github.com/prebid/prebid-cache/version.Rev=$(git rev-parse HEAD)" .

FROM alpine:3.22 AS release
WORKDIR /usr/local/bin/
COPY --from=builder --chmod=544 /build/prebid-cache .
COPY --from=builder --chmod=444 /build/config.yaml .
RUN adduser -D -H prebid_user
USER prebid_user
EXPOSE 2424 2525
ENTRYPOINT ["/usr/local/bin/prebid-cache"]

@decaffeinatedio
Copy link
Author

@linux019 I think your Dockerfile is even cleaner (trimpath is a good improvement, too). I can modify the PR to use that -- my main concerns were targeting ARM and not using a huge Ubuntu base image. Let me know!

@bsardo bsardo self-assigned this Dec 16, 2025
@bsardo
Copy link
Collaborator

bsardo commented Feb 4, 2026

Sorry for the delay here. We finally got around to discussing this in the biweekly PBS-Go Engineering subcommittee meeting. Prebid Server and Cache used Alpine as the base image several years ago before I was part of Prebid. The engineers who were around at that time believe that the switch was made to Ubuntu trading off resource utilization for ease of debugging with the belief being that the resource utilization sacrifice was minimal. Given this fact and that some prominent Prebid members still run with Ubuntu as the base image, we agreed that we should keep Ubuntu as the default base image and continue to publish Ubuntu images we build as part of the release process to Docker Hub. However, we agreed that it would be sensible to provide base image alternatives (e.g. Dockerfile.alpine) for folks that prefer other base images if you would like to modify the PR as such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants