【问题标题】:Unable to clone repository in docker-compose无法在 docker-compose 中克隆存储库
【发布时间】:2021-08-09 20:20:48
【问题描述】:

我正在尝试使用 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

【问题讨论】:

    标签: git docker go docker-compose


    【解决方案1】:

    问题:

    以下命令在您的容器中失败,因为它是一个交互式命令,需要用户为 GitHub 输入 usernamepassword。尽管在您的本地计算机中不是这种情况,但容器内部就是这种情况。我不知道差异的原因?。

    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
    

    步骤:

    1. 更新您的克隆命令以使用上面的 SSH。

    2. 如果您尚未在 Github 配置文件中配置 SSH 密钥,您可以关注 this documentation 进行配置。

      ​⚠️​请确保在此步骤中您能够在本地计算机上使用 SSH 克隆存储库。

    3. 在 docker-compose 文件中更新您的 command 以安装 SSH 客户端

      command: >
        "
          ls
          apk add --update alpine-sdk openssh
          make Tests
        "
      
    4. 如果您使用的是 Mac,请确保您的 ~/.ssh/config 文件中的 IgnoreUnknown UseKeychain 高于 UseKeychain yes

      ℹ️ 原因是您的 Golang Alpine 映像中安装的 openssh 版本无法识别 UseKeychain 选项,并会抛出 Bad configuration option: usekeychain 错误。您可以在this document 中阅读更多相关信息。

      正确的~/.ssh/config 文件示例:

      Host *
        AddKeysToAgent yes
        IgnoreUnknown UseKeychain
        UseKeychain yes
        IdentityFile ~/.ssh/id_rsa
      
    5. 然后更新您的volumes,如下所示:

      volumes:
        - type: bind
          source: ~/go
          target: /go
        - type: bind
          source: .
          target: /app
        - ~/.ssh:/root/.ssh
      

      请注意,您不再需要 ~/.gitconfig:/root/.gitconfig 音量。我还删除了您将 HOME 目录映射到容器的 /root 的映射,因为我仍然怀疑它可能会导致问题。

    我相信这现在应该对你有用。干杯? !!!

    【讨论】:

    • 我不熟悉signingkey。那会是~/.ssh/id_rsa 吗?
    • 哦!对不起,这不是真的必要。当您想要签署提交并验证您是实际提交该提交的人时使用它。那么除此之外,您是否在 gitconfig 中找到了其他属性?你的 gitconfig 的目录是什么?
    • 是的,它在~/.gitconfig
    • 如果你在本地机器上运行git clone https://github.com/MyGithOrg/TestProject /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject,它会在不询问你的github用户名或github密码的情况下克隆你的项目吗?
    • 实际的包gitopenssh需要使用apk安装
    猜你喜欢
    • 1970-01-01
    • 2014-02-20
    • 1970-01-01
    • 2017-10-17
    • 2016-10-09
    • 2015-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多