-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
46 lines (32 loc) · 1.07 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
45
46
# Start from a small, secure base image
FROM golang:1.19-alpine AS builder
# Set the working directory inside the container
WORKDIR /app
# Copy the Go module files
COPY go.mod go.sum ./
# Download the Go module dependencies
RUN go mod download
# Copy the source code into the container
COPY . .
# Build the Go binary
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app ./cmd/port-service/main.go
# Create a minimal production image
FROM alpine:latest
# It's essential to regularly update the packages within the image to include security patches
RUN apk update && apk upgrade
# Reduce image size
RUN rm -rf /var/cache/apk/* && \
rm -rf /tmp/*
# Avoid running code as a root user
RUN adduser -D appuser
USER appuser
# Set the working directory inside the container
WORKDIR /app
# Copy only the necessary files from the builder stage
COPY --from=builder /app/app .
# Set any environment variables required by the application
ENV HTTP_ADDR=:8080
# Expose the port that the application listens on
EXPOSE 8080
# Run the binary when the container starts
CMD ["./app"]