-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
40 lines (28 loc) · 1.19 KB
/
Dockerfile
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
FROM golang:1.12.13-alpine as builder
WORKDIR /go/src/github.com/christian-kreuzberger-dtx/go-mini-server
# Force the go compiler to use modules
ENV GO111MODULE=on
ENV GOPROXY=https://proxy.golang.org
RUN apk add --no-cache gcc libc-dev
# Copy `go.mod` for definitions and `go.sum` to invalidate the next layer
# in case of a change in the dependencies
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy local code to the container image.
COPY . .
# Build the command inside the container.
# (You may fetch or manage dependencies here,
# either manually or with a tool like "godep".)
RUN GOOS=linux go build -ldflags '-linkmode=external' -v main.go
# Use a Docker multi-stage build to create a lean production image.
FROM alpine:3.11
# we need to install ca-certificates and libc6-compat for go programs to work properly
RUN apk add --no-cache ca-certificates libc6-compat
# Copy the binary to the production image from the builder stage.
COPY --from=builder /go/src/github.com/christian-kreuzberger-dtx/go-mini-server/main /main
EXPOSE 8080
# required for external tools to detect this as a go binary
ENV GOTRACEBACK=all
# Run the web service on container startup.
CMD ["/main"]