Docker – Connect GitLab and Gitlab runner, both in Docker

dockergitlab

How can I connect my GitLab installation with a runner, that are both running in separate docker containers?

GitLab is working fine, it is reachable via http://docker.lcnet:8181

My first problem is, where can I find my Gitlab "CI" URL? or is it just my normal URL? Do I have to inlcude the Port?

I'm using this doc:
https://docs.gitlab.com/ce/ci/docker/using_docker_images.html

This is what I get:

ubuntu@docker:~$ sudo docker exec -it gitlab-runner gitlab-runner register

Running in system-mode.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://docker.lcnet:8181
Please enter the gitlab-ci token for this runner:
<token from settings>
Please enter the gitlab-ci description for this runner:
[5bf3c5086904]: my-runner
Please enter the gitlab-ci tags for this runner (comma separated):
tag1
ERROR: Registering runner... failed runner=hm-eFuar status=couldn't execute POST against http://docker.lcnet:8181/ci/api/v1/runners/register.json:                                                                      Post http://docker.lcnet:8181/ci/api/v1/runners/register.json: dial tcp: lookup vader.nts on 8.8.8.8:53: no such host
PANIC: Failed to register this runner. Perhaps you are having network problems

I see that there are network problems but after some hours of searching I couldn't find a decent hint to resolve this problem.
I know that docker images can communicate with each other via docker-names but this isn't mentioned anywhere how to set this up.

I tried to enter "gitlab-ce" (which is the name of the docker container running gitlab) but it won't work.

Do I have to create a docker network?

Best Answer

Ok so after diving into docker more deeply, I understood that I have to link the runner-container to the GitLab container with "link".

This is something that is missing in the docs above. Although it says that running Gitlab and a runner on the same machine isn't suggested (which I guess would also solve the problem), in some scenarios it is needed, so it would be nice to mention that the containers have to be linked:

$ docker run -d -P --name gitlabce gitlab/gitlab-ce:latest
$ docker run -d -P --name runner --link gitlabce:gitlabce gitlab/gitlab-runner:latest

$ docker exec -it runner gitlab-runner register
Running in system-mode.                                                                                                                                                                                                                                       

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):                                                                                                                                                                                        
http://gitlabce  

Please enter the gitlab-ci token for this runner:                                                                                                                                                                                                             
(your token from gitlab->admin->runner) 

Please enter the gitlab-ci description for this runner:                                                                                                                                                                                                       
[a11fa3f389d9]:    

Please enter the gitlab-ci tags for this runner (comma separated):                                                                                                                                                                                            

Registering runner... succeeded                

I'm new to docker so sorry for this trivial question, but maybe it will help others.

Another method would be to create a user defined network, since, if I understood correctly, containers can communicate with each other without links.