-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile.production
32 lines (22 loc) · 936 Bytes
/
Dockerfile.production
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
# Install dependencies and compile to a binary
FROM golang:1.19-alpine as builder
WORKDIR /app
COPY go.sum go.mod ./
RUN go mod download
COPY . .
ENV GIN_MODE=release
# Define the target architecture so it can still be deployed to an x86 machine if compiled on an ARM machine
ENV GOOS=linux GOARCH=amd64
RUN go build -o /bin/gin-air-docker-boilerplate .
# Step 2: build a small image that runs the binary
FROM alpine:3.14
####
## To ensure the application doesn't run as root, we
## create a new user and group that it will run as.
####
RUN addgroup boilerplate-user && adduser -D -G boilerplate-user boilerplate-user
# copy static executable and change the owner to be the user that will run the application
COPY --chown=boilerplate-user:boilerplate-user --from=builder /bin/gin-air-docker-boilerplate /bin/gin-air-docker-boilerplate
USER boilerplate-user:boilerplate-user
EXPOSE 8080
CMD ["/bin/gin-air-docker-boilerplate"]