Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MatthewJamesBoyle/4d6eb1ced1aba7c72b93bfdc3ffdf709 to your computer and use it in GitHub Desktop.
Save MatthewJamesBoyle/4d6eb1ced1aba7c72b93bfdc3ffdf709 to your computer and use it in GitHub Desktop.
dockerfile for josh
# 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