1

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.

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?

Nan Xiao
  • 16,671
  • 18
  • 103
  • 164

1 Answers1

1

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 ':')

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/75772/discussion-between-nan-xiao-and-vonc). – Nan Xiao Apr 21 '15 at 07:29
  • 1
    Very appreciated for your help first! After executing `ssh -p 2222 git@10.137.20.113`, it outputs: `PTY allocation request failed on channel 0 Welcome to GitLab, Administrator! Connection to 10.137.20.113 closed.`. Does it mean the gitlab doesn't provide shell access? – Nan Xiao Apr 21 '15 at 07:33
  • @NanXiao yes, that is perfectly expected and means ssh is properly setup. Those hosting services never provide an interactive ssh session, but allows ssh for git cloning. – VonC Apr 21 '15 at 08:01
  • OK! According to the `gitlab` project webpage, the project ssh address is `git@192.168.59.103:root/test.git`. But I can't clone the project using `git clone git@192.168.59.103:root/test.git` command. I even can't `ping 192.168.59.103` successfully. I also tried `172.17.0.13` and `10.137.20.113`, they also can't work. Could you give some comments? Thanks in advance! – Nan Xiao Apr 21 '15 at 08:08
  • @NanXiao In your case, this should be 10.137.20.113: `git clone ssh://git@10.137.20.113:root/test.git` – VonC Apr 21 '15 at 08:29
  • It still can't work. And the output is: "`Cloning into 'test'... ssh: Could not resolve hostname 10.137.20.113:root: Name or service not known fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. `". I think we should use `2222` port, right? – Nan Xiao Apr 21 '15 at 09:02
  • @NanXiao right, I forgot about the port (http://stackoverflow.com/a/5767880/6309): `git clone git@192.168.59.103:2222:root/test.git`. – VonC Apr 21 '15 at 09:25
  • It should be:"`git clone git@10.137.20.113:2222:root/test.git `", but it prompt input password for `git` user. I have checked the [http://stackoverflow.com/questions/15495843/gitlab-git-user-password](http://stackoverflow.com/questions/15495843/gitlab-git-user-password), but can't find the solution. – Nan Xiao Apr 21 '15 at 09:31
  • @NanXiao strange, considering `ssh -p 2222 git@10.137.20.113` worked without asking for a password. It means the public ssh key isn't registered on the server (or on the root/testing project maybe?) – VonC Apr 21 '15 at 09:33
  • Sorry. "`It means the public ssh key isn't registered on the server (or on the root/testing project maybe?)`", could you explain detailedly? Because I am a newbie for gitlab. Thanks! – Nan Xiao Apr 21 '15 at 09:39
  • @NanXiao I am referring to http://doc.gitlab.com/ce/ssh/README.html or https://about.gitlab.com/2014/03/04/add-ssh-key-screencast/ – VonC Apr 21 '15 at 09:41
  • I have generated the SSH key for `root`, so can I still generate a SSH key for `git` user? – Nan Xiao Apr 21 '15 at 09:45
  • @NanXiao no it should work (unless your public and private key have, locally, a non-standard name, ie not `id_rsa`/`id_rsa.pub`). If that if the case, you would need an `~/.ssh/config` file. – VonC Apr 21 '15 at 10:22
  • I have debugged another day, but still can't figure out the reason. 1) I use `ssh -vvvT -p 2222 git@10.137.20.113`, it works OK: `... Transferred: sent 3248, received 3088 bytes, in 0.3 seconds Bytes per second: sent 12031.9, received 11439.2 debug1: Exit status 0`. 2) When input `git clone git@10.137.20.113:2222:root/test.git` in one terminal, I use `ps` command check in another terminal: `root 22727 22711 0 02:33 pts/5 00:00:00 git clone git@10.137.20.113:2222:root/test.git root 22728 22727 0 02:33 pts/5 00:00:00 ssh git@10.137.20.113 git-upload-pack '2222:root/test.git'`. – Nan Xiao Apr 22 '15 at 06:57
  • My `git` version is `1.8.3.1`, so according to the previous `ps` output, I doubt the `ssh` command is wrong. Could you give any comments? – Nan Xiao Apr 22 '15 at 07:00
  • `git-upload-pack '2222:root/test.git'` seems odd. Could you try with `git clone git@10.137.20.113:2222/root/test.git` just for testing? Also could you check if a more recent version of Git makes any difference? Finally, in order to avoid having to set the port in the url (which might confuses Git), you could try with an `~/.ssh/config` (as in http://stackoverflow.com/a/25855479/6309)? – VonC Apr 22 '15 at 07:07
  • The output of `git clone git@10.137.20.113:2222/root/test.git` is`fatal: destination path 'test' already exists and is not an empty directory.` . I only add `Port 2222` in `~/.ssh/config`, and execute the command `git clone git@10.137.20.113:root/test.git`, the output is `fatal: destination path 'test' already exists and is not an empty directory.` too. I will also check more newer `git` version. – Nan Xiao Apr 22 '15 at 07:39
  • It is OK now. I have created a new empty folder, and entered it. All is OK! So the root cause is I don't use `git clone` command in a empty folder. Thanks very much for your kindly and patient help and advice!! – Nan Xiao Apr 22 '15 at 08:13
  • @NanXiao Great! I have included the conclusion in the answer for more visibility. – VonC Apr 22 '15 at 09:36
  • `git clone git@10.137.20.113:2222/root/test.git` doesn't work in my git (1.8.3.1), I am not sure whether it is OK in higher version. 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`. Then it works OK. – Nan Xiao Apr 22 '15 at 09:42
  • After testing, `git clone ssh://git@10.137.20.113:2222/root/test.git` works OK, no need to add `Port 2222` in config file. Could you test and update your answer? Thanks in advance! – Nan Xiao Apr 23 '15 at 03:09