【发布时间】:2020-03-14 23:58:07
【问题描述】:
这是我的 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
【问题讨论】:
-
问题是在构建时没有安装卷。它们仅在运行容器时可用。这里还有其他信息:github.com/docker/compose/issues/6440
标签: git docker ssh docker-compose