[英]How to access private GitHub repositories in docker-compose?
這是我的 docker-compose.yml 文件:
version: '2.1'
services:
users-db:
container_name: users-db
build: git@github.com:lukalopusina/flask-microservices-users.git#master:project/db
volumes:
- '~/.ssh/github:/root/.ssh/id_rsa'
ports:
- 5435:5432 # expose ports - HOST:CONTAINER
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
healthcheck:
test: exit 0
這是 Dockerfile:
FROM postgres
# Disable checking for known_hosts (maybe not working)
RUN mkdir /root/.ssh && echo "StrictHostKeyChecking no " > /root/.ssh/config
# run create.sql on init
ADD create.sql /docker-entrypoint-initdb.d
當我運行docker-compose up 時,出現以下錯誤:
Building users-db
ERROR: Error trying to use git: exit status 128 (Cloning into '/var/lib/docker/tmp/docker-build-git576570106'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
)
問題可能與 ssh 權限有關,但我將我的 ssh 密鑰作為安裝卷添加到容器中(或者我在那里犯了一些錯誤):
volumes:
- '~/.ssh/github:/root/.ssh/id_rsa'
但它仍然不起作用。 如何解決這個問題?
這是 ~/.ssh 目錄(我的主機)的權限:
drwx------ 2 llopusina llopusina 4096 јун 7 14:22 .ssh
這些是 ~/.ssh (我的主機)中文件的權限:
-rw------- 1 llopusina llopusina 3243 јун 7 14:15 github
-rw-r--r-- 1 llopusina llopusina 749 јун 7 14:15 github.pub
-rw-r--r-- 1 llopusina llopusina 1326 јун 7 14:35 known_hosts
確保.ssh
文件夾和您掛載到容器的密鑰具有正確的權限(文件夾為 700,密鑰文件為 600)並且所有者設置為docker:docker
編輯:看起來像是 docker 守護進程和主機之間的密鑰和上下文問題。 我在docker-compose
發現了這個未解決的問題: https : //github.com/docker/compose/issues/2856
最后的建議是:
僅供報告的任何人使用:這是一個已知問題。 <...> 解決方案是在客戶端進行 git clone。 我們不認為它是高優先級的,但 PR 總是受歡迎的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.