docker git clone during build is not cloning (and not erroring)

Here is the docker git command

  WORKDIR /var/www
  RUN git clone --verbose git@github.com:<private git repo>.git /var/www

The git clone command executes without error but after attaching to the container I can’t find the project in any of the folders. I’ve tried to cd into /var/www before the clone but same result. One odd thing, I expected the the –verbose flag to output the summary details of the project but it does not. So I added a statement to verify the ssh connection:

  • Renew Gogs SSH Key via file replace?
  • Integrate private files for open source application code in devops pipeline
  • using docker plugin on jenkins -
  • Docker clone private repo - Permission denied
  • How to automate docker deployment based on GitHub webhook?
  • How to run Docker inside Jenkins which is running as container
  •   RUN \
        chmod 600 /repo-key && \  
        echo "IdentityFile /repo-key" >> /etc/ssh/ssh_config && \
        echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config && \
        ssh -v git@github.com
    

    It connects successfully, the output:

      Hi willlopez! You've successfully authenticated, but GitHub does not provide shell access.
      debug1: channel 0: free: client-session, nchannels 1
      debug1: fd 0 clearing O_NONBLOCK
      debug1: fd 1 clearing O_NONBLOCK
      debug1: fd 2 clearing O_NONBLOCK
      Transferred: sent 2944, received 1464 bytes, in 0.1 seconds
      Bytes per second: sent 31103.1, received 15467.0
      debug1: Exit status 1
    

    The git clone output:

      Cloning into '/var/www'...
      Warning: Permanently added the RSA host key for IP address to the list of known hosts.
    

    I used nsenter docker-enter to attach to the running container. /var/www is empty

  • Git porcelain commands via pygit2?
  • Why is git not pushing contents of a folder?
  • What is the correct command for performing a git-rebase in this scenario?
  • Git clone over ftps
  • Why is this git push not allowing me to do this?
  • How can I check which commits have not been pushed to origin?
  • 3 Solutions collect form web for “docker git clone during build is not cloning (and not erroring)”

    I think the git clone is working fine, but as /var/www is a volume, the changes are being thrown away. After a volume is declared in a Dockerfile, you can’t make changes to that directory; remember volumes are set up at run time.

    If you move the VOLUME statement after the git clone statement, it will copy the files into the volume. If you can’t do that, you could execute the clone at run time in a CMD or ENTRYPOINT script.

    For more information on volumes, see the official Docker documentation https://docs.docker.com/userguide/dockervolumes/ or this blog http://container-solutions.com/2014/12/understanding-volumes-docker/

    The error is a part of the test. You’re authenticating to GitHub fine.

    Hi MakotoTheKnight! You've successfully authenticated, but GitHub does not provide shell access.
    debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
    debug1: channel 0: free: client-session, nchannels 1
    Connection to github.com closed.
    Transferred: sent 3632, received 1800 bytes, in 0.1 seconds
    Bytes per second: sent 27200.9, received 13480.6
    debug1: Exit status 1
    

    That said, whenever you do git clone, whatever path you have specified for your private Git repo, Git uses that directory by default. It can be overridden by providing a follow-up argument specifying the directory you want to place your code into (e.g. git clone git@github.com:UserName/someproject.git somedirectory.

    If you have write permissions into the directory, your code contents should be in there.
    You can verify the permissions via ls -l, and if you’re the user who owns or are in the same group as the user who owns /var/www, it should work.

    I’ve too stumbled upon the error:

    ERROR: Hi [username]! You've successfully authenticated, but GitHub does not provide shell access Connection to github.com closed.
    

    in the past.

    In my case it was related to setting the GIT_SSH environment variable correctly,
    Perhaps the following link will help you too: github: No supported authentication methods available

    Cheers.

    -Ricardo

    Git Baby is a git and github fan, let's start git clone.