How can I use git client to access gitlab docker?

I have run the gitlab docker image successfully, but couldn’t use git client to access it.

(1) I find there are 3 IP addresses:
a) The host IP: 10.137.20.113;
b) Attach the gitlab running container, show its IP: 172.17.0.13;
c) Log in the webpage, it displays the project address: ssh: git@192.168.59.103:root/test.git.

  • Azk with phpmyadmin
  • Different env-file but same yml with Docker Compose?
  • Jenkins build parameter not working in quotes
  • Why is virtualbox running so slowly under docker?
  • Using a docker container querying an AWS RDS Instance
  • For what sort of volume mounting errors will Docker fail silently?
  • Why is there a IP addr(192.168.59.103)?

    (2) I have added the root user SSH key in the gitlab, but can’t access the server using ssh -p 2222 10.137.20.113 command.

    How can I use git client to access the gitlab?

  • how to add an external IP to a docker container?
  • Using docker GELF driver env/labels in logstash
  • Setting Docker container hostname on Elastic Beanstalk
  • Run Docker by using shell script from remote machine?
  • Mac: how to remotely access server running inside docker container from other computers?
  • Shared library in containers
  • One Solution collect form web for “How can I use git client to access gitlab docker?”

    192.168.59.103 is typical of a boot2docker ip, that is the IP of the VirtualBox machine which hosts the Tiny core Linux running the containers (the ones with the 172.17.0.13)

    If you want to access any ports from a client, you need to make sure:

    • the GitLab container runs with the exposed ports mapped to ports in the Linux host: docker run -p 2222:22 -p 80:80 -p 443:443 ...
    • those ports are redirected in the VirtualBox network definition of “boot2docker-vm” defined in it:

    That would be for example:

    boot2docker stop
    VBoxManage.exe controlvm "boot2docker-vm" natpf1 "udp-port80,udp,,80,,80";
    VBoxManage.exe controlvm "boot2docker-vm" natpf1 "udp-port80,udp,,443,,443";
    

    (same for 443, 2222 should already be exported)

    Otherwise, a client (outside of the VirtualBox) wouldn’t be able to see those ports when accessing 192.168.59.103.

    In the OP case, no need for 192.168.59.103. The IP of the RedHat server is enough (since it directly hosts the docker service).

    ssh -p 2222 10.137.20.113 would only work with the right user (git)

     ssh -p 2222 git@10.137.20.113
    

    And only if the public ssh key has been registered on the server.

    The OP reports in the comments having the error:

    git-upload-pack '2222:root/test.git'
    

    I fix the problem in 2 steps:

    1. add Port 2222 in ~/.ssh/config
    2. Use git clone git@10.137.20.113:root/test.git

    You can see a more complete example of ~/.ssh/config in “git clone using ssh failed in Windows due to permission issue”.

    After testing, this also work:

    git clone ssh://git@10.137.20.113:2222/root/test.git
    

    (so using ‘/‘ instead of ‘:‘)

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.