英文:
Docker alpine golang go get error for coding.net private repo
问题
我使用coding.net创建了私有仓库。
我使用了alpine和centos的docker镜像。
我可以在docker-centos中成功执行go get git.coding.net/alphayan/orionv2.git
,但是在docker-alpine中无法执行go get git.coding.net/alphayan/test.git
,返回了以下错误信息:
/go/src # go get -u -v git.coding.net/alphayan/test.git
cd .; git ls-remote https://git.coding.net/alphayan/test
fatal: could not read Username for 'https://git.coding.net': terminal prompts disabled
cd .; git ls-remote git+ssh://git.coding.net/alphayan/test
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
cd .; git ls-remote ssh://git.coding.net/alphayan/test
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
package git.coding.net/alphayan/test.git: cannot download, git.coding.net/alphayan/test uses insecure protocol
在centos中,它让我输入用户名和密码:
[root@83fc8067fc95 /]# go get -u -v git.coding.net/alphayan/test.git
Username for 'https://git.coding.net':
最后,我发现问题是由于git的版本引起的,centos使用的是git 1.8.3,而alpine使用的是git 2.11.0。
然后我将centos的git版本更改为2.11.0,结果和alpine一样出错了。
我认为我可以修改golang或git的源文件来解决这个问题,有人可以帮助我吗?谢谢!
英文:
I created the private repository using the coding.net.
I use docker images alpine and centos.
I can go get git.coding.net/alphayan/orionv2.git successful
from docker-centos, but I can't go get git.coding.net/alphayan/test.git
from docker-alpine.It returns an error stating:
/go/src # go get -u -v git.coding.net/alphayan/test.git
# cd .; git ls-remote https://git.coding.net/alphayan/test
fatal: could not read Username for 'https://git.coding.net': terminal prompts disabled
# cd .; git ls-remote git+ssh://git.coding.net/alphayan/test
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
# cd .; git ls-remote ssh://git.coding.net/alphayan/test
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
package git.coding.net/alphayan/test.git: cannot download, git.coding.net/alphayan/test uses insecure protocol
From centos it let me use the username and password:
[root@83fc8067fc95 /]# go get -u -v git.coding.net/alphayan/test.git
Username for 'https://git.coding.net':
finally, I find it caused by the git's version, the centos with git 1.8.3 and the alpine with git 2.11.0.
then I change the centos git's version with 2.11.0, becomes the same wrong with alpine.
I think I can modify golang or git source file solve this problem,
could someone help me? thinks~!
答案1
得分: 4
这个错误是因为默认情况下,go get
命令不使用终端输入。可以通过修改环境变量 GIT_TERMINAL_PROMPT
来改变这种行为,该环境变量在 git 2.3 中引入。这就是为什么在 CentOS 7(git 1.8)和 Alpine 3.5(git 2.11)中,go get
命令的行为不同的原因。
在 git >= 2.3
中,你可以通过以下方式解决这个问题:
$ GIT_TERMINAL_PROMPT=1 go get github.com/foo/bar
Username for 'https://github.com':
如果你有多个 go get
命令,你可以在运行命令之前导出该环境变量:
$ export GIT_TERMINAL_PROMPT=1
$ go get github.com/foo/bar
Username for 'https://github.com':
$ go get github.com/foo/baz
Username for 'https://github.com':
英文:
This error happens because by default go get
doesn't use terminal input. This behaviour can be changed by modifying environment variable GIT_TERMINAL_PROMPT
, which was introduced in git 2.3. That's why the go get
command behaves differently in CentOS 7 (git 1.8) and Alpine 3.5 (git 2.11).
You can work your way around the issue in git >= 2.3
by running go get
as follows:
$ GIT_TERMINAL_PROMPT=1 go get github.com/foo/bar
Username for 'https://github.com':
If you have multiple go get
calls then you can export that environment variable before running the commands:
$ export GIT_TERMINAL_PROMPT=1
$ go get github.com/foo/bar
Username for 'https://github.com':
$ go get github.com/foo/baz
Username for 'https://github.com':
答案2
得分: 3
你可以尝试使用ssh,如果你的公共ssh密钥已在coding.net上注册。
以"在docker中获取私有存储库"为例:
FROM golang:1.6
RUN echo "\n\tinsteadOf = https://github.com/" >> /root/.gitconfig
RUN mkdir /root/.ssh && echo "StrictHostKeyChecking no " > /root/.ssh/config
ADD . /go/src/github.com/company/foo
CMD cd /go/src/github.com/company/foo && go get github.com/company/bar && go build -o /foo
使用以下构建步骤:
docker build -t foo-build .
docker run --name=foo-build -v ~/.ssh/id_rsa:/root/.ssh/id_rsa foo-build
docker cp foo-build:/foo foo
docker rm -f foo-build
docker rmi -f foo-build
英文:
You could try through ssh, if your public ssh key is registered on coding.net.
See "go get for private repos in docker" as an example:
FROM golang:1.6
RUN echo "\n\tinsteadOf = https://github.com/" >> /root/.gitconfig
RUN mkdir /root/.ssh && echo "StrictHostKeyChecking no " > /root/.ssh/config
ADD . /go/src/github.com/company/foo
CMD cd /go/src/github.com/company/foo && go get github.com/company/bar && go build -o /foo
with the build step:
docker build -t foo-build .
docker run --name=foo-build -v ~/.ssh/id_rsa:/root/.ssh/id_rsa foo-build
docker cp foo-build:/foo foo
docker rm -f foo-build
docker rmi -f foo-build
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论