-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
39 lines (28 loc) · 914 Bytes
/
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
# Start from golang base image
FROM golang:alpine as builder
# Enable go modules
ENV GO111MODULE=on
# Set current working directory
WORKDIR /app
# Note here: To avoid downloading dependencies every time we
# build image. Here, we are caching all the dependencies by
# first copying go.mod and go.sum files and downloading them,
# to be used every time we build the image if the dependencies
# are not changed.
# Copy go mod and sum files
COPY go.mod ./
COPY go.sum ./
# Download all dependencies.
RUN go mod download
# Now, copy the source code
COPY . .
# Build the application.
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/main .
# Finally our multi-stage to build a small image
# Start a new stage from scratch
FROM scratch
# Copy the Pre-built binary file
COPY --from=builder /app/bin/main .
# Run executable
CMD ["./main", "--port", "5000", "--path", "/data/static-files"]
EXPOSE 5000