-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
35 lines (24 loc) · 1 KB
/
Copy pathDockerfile
File metadata and controls
35 lines (24 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Tunnel server — multi-stage: compile in Go image, ship only the static binary.
#
# Final image (~10MB): no Alpine, no shell, no Go toolchain — only mytunneld + distroless base.
# During `docker build`, Docker may still cache the *builder* image (golang:…) on the host;
# that is not inside the pushed/runnable image. Remove leftovers: docker image prune -f
#
# Build: docker build -t mytunneld .
# Run: docker run -d --name mytunneld -p 3000:3000 -p 9000:9000 mytunneld
# syntax=docker/dockerfile:1
ARG GO_VERSION=1.25
FROM golang:${GO_VERSION}-alpine AS build
WORKDIR /src
RUN apk add --no-cache git ca-certificates
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux \
go build -trimpath -ldflags="-s -w" \
-o /mytunneld ./cmd/server
# Smallest practical runtime: no package manager, non-root (uid 65532).
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build --chown=65532:65532 /mytunneld /mytunneld
EXPOSE 3000/tcp 9000/tcp
ENTRYPOINT ["/mytunneld"]