blob: bb4712f877ec92750e1b28b6af911939dc64349d (
plain) (
blame)
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
|
FROM golang:1.16-alpine AS builder
COPY ${PWD} /app
WORKDIR /app
# Toggle CGO based on your app requirement. CGO_ENABLED=1 for enabling CGO
RUN CGO_ENABLED=0 go build -ldflags '-s -w -extldflags "-static"' -o /app/appbin *.go
# Use below if using vendor
# RUN CGO_ENABLED=0 go build -mod=vendor -ldflags '-s -w -extldflags "-static"' -o /app/appbin *.go
FROM alpine:latest
# Following commands are for installing CA certs (for proper functioning of HTTPS and other TLS)
RUN apk --update add ca-certificates && \
rm -rf /var/cache/apk/*
# Add new user 'appuser'
RUN adduser -D appuser
USER appuser
COPY --from=builder /app /home/appuser/app
WORKDIR /home/appuser/app
# Since running as a non-root user, port bindings < 1024 is not possible
# 8000 for HTTP; 8443 for HTTPS;
EXPOSE 3000
CMD ["./appbin"]
|