I have a monorepo that has holds various Go services and libraries. It has a structure of
monorepo
services
service-a
- Dockerfile
go.mod
go.sum
My go.mod resides in the root of the monorepo and the services use the dependencies stated in the go.mod file.
I build the Docker image with
docker build -t some:tag ./services/service-a/
When I try to build my Docker image from the root of the monorepo with the above docker command I get the following error.
COPY failed: Forbidden path outside the build context: ../../go.mod ()
Below is my Dockerfile
FROM golang:1.14.1-alpine3.11
RUN apk add --no-cache ca-certificates git
# Enable Go Modules
ENV GO111MODULE=on
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy go mod and sum files
COPY ../../go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o service-a
ENTRYPOINT ["/app/service-a"]
Is there something I have to do to be able to add files into my Docker image that aren't in the current directory without having to have a separate go.mod and go.sum in each service within the monorepo?