-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
44 lines (31 loc) · 1.12 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
41
42
43
44
# for more information about go docker apk images: https://www.callicoder.com/docker-golang-image-container-example/
# build image to construct binary executable
FROM golang:latest as builder
LABEL maintainer="Leonard Pahlke <[email protected]>"
# execute further commands inside /app directory
WORKDIR /app
# copy go.mod file to download dependecies
COPY go.mod go.sum ./
# download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download
# copy everything in the root directory into the workingdirectory directory
COPY . .
# run go build to compile the binary executable
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./cmd
# ---------------------------
# final image is smaller in size
FROM alpine:latest
# update application and add git
RUN apk --no-cache add ca-certificates
# set working directory
WORKDIR /root/
# copy build executables
COPY --from=builder /app/main .
# set default enviorment variables
ENV USERID exampleUser
ENV ENDPOINT localhost:8080
ENV CONNECT null
# expose default port
EXPOSE 8080
# execute binary
CMD ["./main"]