Skip to content

Instantly share code, notes, and snippets.

@nenodias
Created March 26, 2024 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nenodias/cc701e6dfb91b9318b97ca7396fd3eda to your computer and use it in GitHub Desktop.
Save nenodias/cc701e6dfb91b9318b97ca7396fd3eda to your computer and use it in GitHub Desktop.
Golang DockerFile
FROM debian:12-slim as builder
RUN apt update && apt install -y --no-install-recommends \
ca-certificates \
git \
wget \
tar \
gcc \
g++ \
make \
build-essential \
&& rm -rf /var/lib/apt/lists/*
RUN wget https://go.dev/dl/go1.22.1.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.22.1.linux-amd64.tar.gz && rm go1.22.1.linux-amd64.tar.gz
ENV PATH=$PATH:/usr/local/go/bin
WORKDIR /app
RUN addgroup app
RUN useradd -ms /bin/bash app -g app -d /app
COPY ./src/ .
RUN go mod tidy
RUN go test ./...
RUN go vet ./...
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o main .
RUN chmod +x main
FROM cgr.dev/chainguard/glibc-dynamic
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
USER nonroot
COPY --from=builder --chown=nonroot:nonroot /app/main /main
CMD ["./main" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment