Building a docker image to run go applications


I am building a docker image on mac OS (Monterrey) with below dockerfile

FROM golang:latest
COPY go.* ./ 
RUN go mod download 
COPY . /src
RUN go build -o /main
ENTRYPOINT ["/main"]

It works fine til the 3rd line and on the 4th it complains of

=> ERROR [4/6] RUN go mod download                                                         0.2s
 > [4/6] RUN go mod download:
#8 0.206 go mod download: no modules specified (see 'go help mod download')
executor failed running [/bin/sh -c go mod download]: exit code: 1

Any clues what I am doing wrong while the dependencies are being downloaded?


I was missing couple of files from the Working directory as listed below. These are needed to download the dependencies.

Dockerfile //this was already in the folder. 

Answered By – cloud jockey

Answer Checked By – David Marino (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.