简体   繁体   中英

Point to local dependency from remote base image when building Go program Docker image

Please note that I am new to Golang and Docker development. I have already asked this elsewhere and tried to read the documentation but can't find any solution.

The problem and code

I have two repos /home/experience/keep-ecdsa and /home/experience/keep-core which I forked from this project and cloned locally.

I'm trying to build a docker image for keep-ecdsa locally. Here is a link to my forked repo .

There are some keep-core dependencies and I want to point to my local keep-core repo. As such, I changed my go.mod to:

module github.com/keep-network/keep-ecdsa
go 1.13
replace (
    //unrelated stuff...
    github.com/keep-network/keep-core => /home/experience/keep-core
)
require (
    //unrelated stuff...
    github.com/keep-network/keep-core v1.1.3
)

The DOCKERFILE starts as follow (click here to see the full file) :

FROM golang:1.13.8-alpine3.10 AS runtime

ENV APP_NAME=keep-ecdsa \
    BIN_PATH=/usr/local/bin

FROM runtime AS gobuild

ENV GOPATH=/go \
    GOBIN=/go/bin \
    APP_NAME=keep-ecdsa \
    APP_DIR=/go/src/github.com/keep-network/keep-ecdsa \
    BIN_PATH=/usr/local/bin \
    # GO111MODULE required to support go modules
    GO111MODULE=on
    //rest of the linked DOCKERFILE

When running docker build. , I get the error below which occurs at the RUN go mod download step of the DOCKERFILE .

Step 13/27 : RUN go mod download
--> Running in 88839fc42d4e
go: github.com/keep-network/keep-core@v1.1.3: parsing /home/experience/keep-core/go.mod: open /home/experience/keep-core/go.mod: no such file or directory
The command '/bin/sh -c go mod download' returned a non-zero code: 1

What I have attempted and a lead

I have tried to:

  • Change my GOPATH in the DOCKERFILE to various absolute local fs paths
  • Make my APPDIR in the DOCKERFILE point to my absolute local path /home/experience/keep-ecdsa
  • Change the path in the replace ( ) statement of the go.mod to various paths (absolute local, relative to GOPATH , etc

Someone gave me this lead:

you are inside a golang:1.13.8-alpine3.10 base image so there is no /home/experience/keep-core inside there since that is only on your local fs

But I still have no idea how to achieve wat I want. Perhaps replace the FROM... AS runtine statement in the DOCKERFILE by some local base image? But how do I find such relevant base image, and won't it change the rest of the DOCKERFILE instructions?

Keep in mind that I'm going to do local changes to the keep-core dependencies and will need to test them, so a solution that would consist in replace (github.com/mygithubprofile/keep-core) is not satisfactory.

Thank you in advance.

you are inside a golang:1.13.8-alpine3.10 base image so there is no /home/experience/keep-core inside there since that is only on your local fs

From what I can see in the file, you have not copied the /home/experience/keep-core directory on your machine to your docker image so it is throwing up the error as that directory does not exist yet.

Docker cannot follow links outside the directory of the current context so if you do not want to edit replace (github.com/mygithubprofile/keep-core) you can move your DockerFile to /home/experience/ and use the COPY command to copy keep-core folder from your local machine to the docker image.

RUN mkdir -p /home/experience/keep-core
COPY ./keep-core /home/experience/keep-core

However, if you want the DockerFile to remain in /home/experience/keep-ecdsa you could move the keep-core folder into the keep-ecdsa folder and ignore it in .gitignore file. Then update

replace (
    //unrelated stuff...
    github.com/keep-network/keep-core => /home/experience/keep-core
)

TO

replace (
    //unrelated stuff...
    github.com/keep-network/keep-core => /home/experience/keep-ecdsa/keep-core
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM