如何访问docker-compose中的私有GitHub存储库?
这是我的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时,出现以下错误:
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
最后的build议是: FYI to anyone reporting: this is a known issue. <...> the solution is to do the git clone on the client side. We don't consider it high-priority, but PRs are always welcome.
FYI to anyone reporting: this is a known issue. <...> the solution is to do the git clone on the client side. We don't consider it high-priority, but PRs are always welcome.