I have this structure of my project: https://i.stack.imgur.com/SqqDh.png
And this is my Dockerfile:
FROM golang:1.19
ADD . /go/src/myapp
WORKDIR /go/src/myapp
RUN go mod init cloudmeta
RUN go get github.com/go-sql-driver/mysql
RUN go get -u github.com/gin-gonic/gin
RUN go build -o bin/cloudmeta
CMD [ "bin/cloudmeta" ]
When I trying to build my docker-container I have this error:
package cloudmeta/backend/handlers is not in GOROOT (/usr/local/go/src/cloudmeta/backend/handlers)
go mod initin your build process. Get your build working locally (outside docker),go mod init,go get ...etc. which will creatego.mod&go.sum- then these files should pull in the correct dependencies in your docker build, since those files are copied along with your go source.mod inittoRUN go mod init cloudmeta/backend(note that I agree that this is not a good approach, but felt it was worth pointing out why it does not work).