这是我的 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 key 作为挂载卷添加到容器中(或者我在那里犯了一些错误):
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
文件夹和您安装到容器的 key 具有正确的权限(文件夹为 700, key 文件为 600)并且所有者设置为 docker:docker
编辑:
它看起来像是 docker 守护进程和主机之间的键和上下文问题。我在 docker-compose
中发现了这个 Unresolved 问题:
https://github.com/docker/compose/issues/2856
最终推荐的地方是:
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.
关于git - 如何在 docker-compose 中访问私有(private) GitHub 存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44761505/