diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-03-18 02:06:42 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-03-18 02:06:42 +0300 |
commit | 6f31f35c7b38fbf63d7a0c9322458e0b75828495 (patch) | |
tree | 2fcb8cb31bb6604e85cf390dbc01f2e9a8b26ee7 /Dockerfile |
Initial
Diffstat (limited to 'Dockerfile')
-rw-r--r-- | Dockerfile | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bb4712f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,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"] |