英文:
Unable to clone repository in docker-compose
问题
我正在尝试使用docker-compose在localstack上配置一个应用程序。当我尝试克隆存储库时,出现了一个错误。
setup-resources_1 | make[1]: [/app/ProjectRecipes.mk:35: clean] Error 2 (ignored)
setup-resources_1 | ServiceName=Tests make -C /app/ -f /app/ProjectRecipes.mk deploy
setup-resources_1 | git clone https://github.com/MyGithOrg/TestProject /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject
setup-resources_1 | Cloning into '/Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject'...
localstack_1 | Waiting for all LocalStack services to be ready
setup-resources_1 | fatal: could not read Username for 'https://github.com': No such device or address
setup-resources_1 | make[4]: *** [/app/ProjectRecipes.mk:24: /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject] Error 128
docker-compose.yml
version: '3'
services:
localstack:
image: localstack/localstack
ports:
- "53:53"
- "443:443"
- "4510-4520:4510-4520"
- "4566-4620:4566-4620"
- "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
environment:
- LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY}
- SERVICES=serverless,rds,lambda,sqs,dynamodb,s3,apigateway,stepfunctions,cloudformation,appsync,firehose,es
- DEBUG=1
- DATA_DIR=/tmp/localstack/data
- DOCKER_HOST=unix:///var/run/docker.sock
- HOST_TMP_FOLDER=${TMPDIR}
volumes:
- "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
- default
setup-resources:
image: golang:1.16.4-alpine3.13
entrypoint: /bin/sh -c
working_dir: /app
command: >
"
ls
apk add --update alpine-sdk
make Tests
"
networks:
- default
volumes:
- type: bind
source: ~/go
target: /go
- type: bind
source: ${HOME}
target: /root
- type: bind
source: .
target: /app
- ~/.ssh:/root/.ssh
- ~/.gitconfig:/root/.gitconfig
depends_on:
- localstack
请注意,这是一个错误消息和docker-compose.yml文件的示例。
英文:
I'm trying to configure an app to run on localstack using docker-compose. I'm getting an error when attempting to clone the resository.
setup-resources_1 | make[1]: [/app/ProjectRecipes.mk:35: clean] Error 2 (ignored)
setup-resources_1 | ServiceName=Tests make -C /app/ -f /app/ProjectRecipes.mk deploy
setup-resources_1 | git clone https://github.com/MyGithOrg/TestProject /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject
setup-resources_1 | Cloning into '/Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject'...
localstack_1 | Waiting for all LocalStack services to be ready
setup-resources_1 | fatal: could not read Username for 'https://github.com': No such device or address
setup-resources_1 | make[4]: *** [/app/ProjectRecipes.mk:24: /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject] Error 128
docker-compose.yml
version: '3'
services:
localstack:
image: localstack/localstack
ports:
- "53:53"
- "443:443"
- "4510-4520:4510-4520"
- "4566-4620:4566-4620"
- "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
environment:
- LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY}
- SERVICES=serverless,rds,lambda,sqs,dynamodb,s3,apigateway,stepfunctions,cloudformation,appsync,firehose,es
- DEBUG=1
- DATA_DIR=/tmp/localstack/data
- DOCKER_HOST=unix:///var/run/docker.sock
- HOST_TMP_FOLDER=${TMPDIR}
volumes:
- "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
- default
setup-resources:
image: golang:1.16.4-alpine3.13
entrypoint: /bin/sh -c
working_dir: /app
command: >
"
ls
apk add --update alpine-sdk
make Tests
"
networks:
- default
volumes:
- type: bind
source: ~/go
target: /go
- type: bind
source: ${HOME}
target: /root
- type: bind
source: .
target: /app
- ~/.ssh:/root/.ssh
- ~/.gitconfig:/root/.gitconfig
depends_on:
- localstack
答案1
得分: 1
问题:
以下命令在容器中失败,因为它是一个交互式命令,需要用户输入GitHub的用户名
和密码
。尽管在本地机器上不是这样,但在容器内是这样的。我不知道这种差异的原因 😕。
git clone https://github.com/MyGithOrg/TestProject /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject
解决方案:
您可以使用以下命令通过SSH克隆您的存储库:
git clone ssh://git@github.com/MyGithOrg/TestProject.git /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject
步骤:
-
更新您的克隆命令以使用上述SSH。
-
如果您尚未在Github配置SSH密钥,可以按照此文档进行配置。
> ⚠️ 确保在此步骤中,您能够在本地机器上使用SSH克隆存储库。
-
更新docker-compose文件中的
command
以安装SSH客户端command: > " ls apk add --update alpine-sdk openssh make Tests "
-
如果您使用的是Mac,请确保在
~/.ssh/config
文件中将IgnoreUnknown UseKeychain
放在UseKeychain yes
之前。> ℹ️ 原因是您在Golang Alpine镜像中安装的
openssh
版本不识别UseKeychain
选项,并且会抛出Bad configuration option: usekeychain
错误。您可以在此文档中了解更多信息。正确的
~/.ssh/config
文件示例:Host * AddKeysToAgent yes IgnoreUnknown UseKeychain UseKeychain yes IdentityFile ~/.ssh/id_rsa
-
然后按照以下方式更新您的
volumes
:volumes: - type: bind source: ~/go target: /go - type: bind source: . target: /app - ~/.ssh:/root/.ssh
请注意,您不再需要
~/.gitconfig:/root/.gitconfig
卷。我还删除了将HOME
目录映射到容器的/root
的映射,因为我仍然怀疑它可能会引起问题。
我相信现在这应该对您有用。祝您好运 🍻 !!!
英文:
Problem:
The following command fails in your container because it is an interactive command that expects the user to enter username
and password
for GitHub. Although this is not the case in your local machine, that is the case inside the container. I don't know the reason for the difference 😕.
git clone https://github.com/MyGithOrg/TestProject /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject
Solution:
You can clone your repository through SSH using the following command:
git clone ssh://git@github.com/MyGithOrg/TestProject.git /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject
Steps:
-
Update your clone command to use SSH like above.
-
If you haven't configured an SSH key in your Github profile, you can follow this documentation to do so.
> ⚠️ Make sure at this step you are able to clone the repo using SSH in your local machine.
-
Update your
command
in docker-compose file to install an SSH clientcommand: > " ls apk add --update alpine-sdk openssh make Tests "
-
If you're using a Mac, then make sure you have
IgnoreUnknown UseKeychain
aboveUseKeychain yes
in your~/.ssh/config
file.> ℹ️ The reason is that
openssh
version that is being installed in your Golang Alpine image does not recognizeUseKeychain
option and will throw youBad configuration option: usekeychain
error. You can read more about that in this document.Example of a correct
~/.ssh/config
file:Host * AddKeysToAgent yes IgnoreUnknown UseKeychain UseKeychain yes IdentityFile ~/.ssh/id_rsa
-
Then update your
volumes
like below:volumes: - type: bind source: ~/go target: /go - type: bind source: . target: /app - ~/.ssh:/root/.ssh
Note that you no longer need
~/.gitconfig:/root/.gitconfig
volume. I also removed your mapping ofHOME
directory to/root
of the container because I still doubt that it might cause issues.
I believe this should work for you now. Cheers 🍻 !!!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论