2017-02-23 35 views
3

我使用codes.net創建了私有存儲庫。
我使用碼頭圖像高山分區
我可以得到碼頭工人,CentOS的git.coding.net/alphayan/orionv2.git successful,但我不能去從docker-alpine.It得到git.coding.net/alphayan/test.git返回一個錯誤,指出:Docker高山golang去編碼.NET私人回購得到錯誤

/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的它讓我使用用戶名和密碼:

[[email protected] /]# go get -u -v git.coding.net/alphayan/test.git 
Username for 'https://git.coding.net': 

最後,我發現它是由git的版本引起的,使用git 1.8.3的centos和使用git 2.11.0的alpine。
然後我用2.11.0改變了centos git的版本,與高山變成了一樣的錯誤。 我想我可以修改golang或者git源文件解決這個問題, 有人可以幫我嗎?認爲〜!

+0

有什麼錯誤?也看起來你有一個私人的git回購 –

+0

使用高山,git的版本是2.11,它不需要我輸入用戶名和密碼,然後我不能去獲取代碼;但使用centos,git的版本是1.8.3,它提示我輸入用戶名和密碼,然後我得到代碼。我將git版本2.11更改爲centos,它將與alpine.I同樣的東西發現它是git的錯誤 – alphayan

回答

3

這個錯誤是因爲在默認情況下go getdoesn't use terminal input。可以通過修改git 2.3中引入的環境變量GIT_TERMINAL_PROMPT來更改此行爲。這就是爲什麼go get命令在CentOS 7(git 1.8)和Alpine 3.5(git 2.11)中表現不同的原因。

您可以通過運行go get如下工作的方式解決此問題在git >= 2.3

$ 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': 

$ GIT_TERMINAL_PROMPT=1 go get github.com/foo/bar 
Username for 'https://github.com': 

如果你有多個go get調用,那麼您可以在環境變量在運行命令之前導出

+0

這似乎比我的答案更精確。 +1 – VonC

+0

非常感謝。 – alphayan

1

你可以試試通過ssh,如果你的public ssh key is registered on coding.net

請參閱 「go get for private repos in docker」 爲例:

FROM golang:1.6 

RUN echo "[url \"[email protected]:\"]\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 
+0

是的,通過ssh它將是正確的。我發現在git版本1.8.4之後,'go get'不能從私人repo獲得代碼成功,但使用'git clone'它會得到代碼。我不知道它是git或golang的錯誤。 – alphayan

+0

@alphayan我也不知道,但如果允許前進,這個答案可能是一個解決方案。 – VonC