Created
February 1, 2024 20:53
-
-
Save MatthewJamesBoyle/4d6eb1ced1aba7c72b93bfdc3ffdf709 to your computer and use it in GitHub Desktop.
dockerfile for josh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Start from the official Go image to build your application | |
FROM golang:1.21 as builder | |
# Set the Current Working Directory inside the container | |
WORKDIR /app | |
# Copy go mod and sum files | |
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 the source from the current directory to the Working Directory inside the container | |
COPY . . | |
# Build the Go app | |
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp ./cmd | |
# Start a new stage from scratch | |
FROM alpine:latest | |
# Install ca-certificates | |
RUN apk --no-cache add ca-certificates | |
WORKDIR /root/ | |
# Copy the Pre-built binary file from the previous stage | |
COPY --from=builder /app/myapp . | |
# Command to run the executable | |
CMD ["./myapp"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment