这是我的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
答案 0 :(得分:0)
确保.ssh
文件夹和您装入容器的密钥具有正确的权限(文件夹为700,密钥文件为600),所有者设置为docker:docker
EDITED:
它看起来像docker守护进程和主机之间的键和上下文的问题。我在docker-compose
中发现了这个未解决的问题:
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.