skip to Main Content

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

FROM golang:latest
WORKDIR /src
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?

2

Answers


  1. Chosen as BEST ANSWER

    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. 
    go.sum
    go.mod
    main.go
    

  2. Instead of using download do :

    go mod tidy && go mod vendor
    

    You need to specify which package to download when you use "mod download"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search