简体   繁体   中英

Unable to clone repository in docker-compose

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

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:

  1. Update your clone command to use SSH like above.

  2. 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.

  3. Update your command in docker-compose file to install an SSH client

    command: > " ls apk add --update alpine-sdk openssh make Tests "
  4. If you're using a Mac, then make sure you have IgnoreUnknown UseKeychain above UseKeychain yes in your ~/.ssh/config file.

    ℹ️ The reason is that openssh version that is being installed in your Golang Alpine image does not recognize UseKeychain option and will throw you Bad 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
  5. 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 of HOME directory to /root of the container because I still doubt that it might cause issues.

I believe this should work for you now. Cheers !!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM