Skip to content

Instantly share code, notes, and snippets.

@anjilinux
Forked from nandanrao/Dockerfile
Created April 6, 2024 13:52
Show Gist options
  • Save anjilinux/d23c79ea8b6860e9607afe0bc3ac213f to your computer and use it in GitHub Desktop.
Save anjilinux/d23c79ea8b6860e9607afe0bc3ac213f to your computer and use it in GitHub Desktop.
Multi-stage build Dockerfile for Go and Kafka with confluent-kafka-go and Alpine
FROM golang:alpine AS build
RUN sed -i -e 's/v[[:digit:]]\..*\//edge\//g' /etc/apk/repositories
RUN apk upgrade --update-cache --available
RUN apk add --no-cache \
gcc \
libc-dev \
librdkafka-dev=1.3.0-r0 \
pkgconf
RUN mkdir /app
WORKDIR /app
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . /app/
RUN go build -o main .
FROM alpine
RUN sed -i -e 's/v[[:digit:]]\..*\//edge\//g' /etc/apk/repositories
RUN apk upgrade --update-cache --available
RUN apk add --no-cache \
librdkafka-dev=1.3.0-r0
WORKDIR /app
COPY --from=build /app/main /app/
CMD ["/app/main"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment