79622014

Date: 2025-05-14 17:47:26
Score: 1
Natty:
Report link

Correct Docker file

FROM golang:1.21-alpine

# Set the working directory

WORKDIR /app

# Copy go.mod and go.sum first (to cache dependencies)

COPY go.mod go.sum ./

# Download dependencies

RUN go mod download

# Copy the rest of the application code

COPY . .

# Build the application

RUN go build -o main .

# Set environment variable and expose port

ENV PORT 8080

EXPOSE 8080

# Run the application

CMD ["./main"]

Steps to Prepare Your Code

1. In your project root (where your Go code is), run:

go mod init example-app

go mod tidy

This creates go.mod and go.sum.

2. Then rebuild your Docker image:

docker build --dns=8.8.8.8 -t test .

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Anmol