Docker: go get from a private GitHub repo

后端 未结 4 1167
天涯浪人
天涯浪人 2021-02-19 06:17

I\'m trying to run a container that will expose a golang service from a package that I have on a private GitHub repo.

Since I am working with GCE, my starter image is g

4条回答
  •  眼角桃花
    2021-02-19 07:13

    I figured this out after a bit of hacking around. Not an ideal solution as it involves installing SSH, plus building a private key into the container. This example is based on the official Docker golang image (Debian Wheezy):

    The main difference to your example is that you need a git config command to force ssh instead of the default https.

    FROM golang
    
    RUN apt-get update && apt-get install -y ca-certificates git-core ssh
    
    ADD keys/my_key_rsa /root/.ssh/id_rsa
    RUN chmod 700 /root/.ssh/id_rsa
    RUN echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config
    RUN git config --global url.ssh://git@github.com/.insteadOf https://github.com/
    
    ADD . /go/src/github.com/myaccount/myprivaterepo
    
    RUN go get github.com/myaccount/myprivaterepo
    RUN go install github.com/myaccount/myprivaterepo
    

提交回复
热议问题