-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile-scratch
41 lines (29 loc) · 1.06 KB
/
Dockerfile-scratch
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
36
37
38
39
40
41
## We specify the base image we need for our
## go application
FROM golang:1.20.5-alpine as builder
RUN apk --no-cache add ca-certificates
# add a user here because addgroup and adduser are not available in scratch
RUN addgroup -S goapp \
&& adduser -S -u 12345 -g goapp goapp
## We specify that we now wish to execute
## any further commands inside our /app
## directory
WORKDIR /app
## Add this go mod download command to pull in any dependencies
COPY go.* ./
RUN go mod download
COPY *.go ./
## we run go build to compile the binary
## executable of our Go program
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /server .
# Deploy the application binary into a lean image
FROM scratch
# Copy the binary to the production image from the builder stage.
COPY --from=builder /server .
# Copy CA certificattes from the builder image
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Copy users from builder image
COPY --from=builder /etc/passwd /etc/passwd
USER goapp
# Run the web service on container startup.
ENTRYPOINT ["/server"]