-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
33 lines (23 loc) · 806 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
# Start from a base image with Go installed
FROM golang:1.21.3-alpine AS builder
# Set the working directory inside the container
WORKDIR /app
# Copy go.mod and go.sum and download dependencies (if using modules)
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the source code
COPY . .
# Build the Go app
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp .
# Start a new stage from scratch for a smaller final image
FROM alpine:latest
# Set the working directory in the new stage
WORKDIR /root/
# COPY the .env file here in the final stage
COPY --from=builder /app/.env .
# Copy the pre-built binary file from the previous stage
COPY --from=builder /app/myapp .
# Expose port 8080 to the outside world
EXPOSE 8080
# Command to run the executable
CMD ["./myapp"]