project_dir/ ├── prj1/ │ ├── go/ │ ├─ |─ go.mod │ ├─ |─ main.go │ └─ |─ ... │ └── ... ├── prj2/ │ ├── go.mod │ ├── main.go │ └── Dockerfile │ └── ... └── ...
The code in prj2 is referencing a function from prj1 via the go mod edit -replace command. Now, this works fine locally but I need to deploy with Docker and I am facing issues.
My docker scripts look like this:
FROM golang:1.17.5 as builder WORKDIR /app COPY go.* ./ ADD ./prj1 ./prj1 RUN go mod download ...
Initially, I was running
docker build . from inside prj2 without the
ADD command in the docker file but
RUN go mod download fails with:
go mod download: email@example.com (replaced by …/prj1/go/): reading /prj1/go/go.mod: open /prj1/go/go.mod: no such file or directory
So, I added the
ADD command to the docker file to copy prj1. Next, I went back to project_dir and ran
docker build -f ./prj2/Dockerfile but
RUN go mod download is now failing with
go mod download: no modules specified (see ‘go help mod download’)
So basically, my question is, how do I tell the go command that the go.mod is inside prj2?
Correct project structure