Change all project URLs to use IP address

Hello all,

I have a (hopefully) very minor problem: I installed Gitlab:CE on docker and at some point during the install, I must have entered my dynDNS address, which I am not currently using. Now, of course, the URL line reads [dynDNS]/[group]/[project], which becomes a problem, when a) my users copy the link and b) when Gitlab Runner tries to clone the repository. I would rather have it be [IP:Port]/[group]/[project]

How can I rewrite the url?

I tried several places already. When I set the external_url in the gitlab.rb, the container wouldn’t start up again. I searched the directory for the ddns string and found two other entries, gitlab-rails\etc\gitlab.yml and nginx\conf\gitlab-http.conf, but when I replaced the address with the IP address, nothing changed.

Any help is greatly appreciated.

In the file gitlab.rb modify the external_url line with the required value.

Ex:
external_url 'http://10.1.1.1:90/'

In this case, consider which port was defined when creating the container, if the container was created with port 90, you should only execute the following statement:

# gitlab-ctl reconfigure
# gitlab-ctl restart

Otherwise, if the container was created with another port, you must recreate the container with the new port:

ports:
   - "80:90"

Consider that port 90 is just an example to explain that the port that you define in the clause external_url, is the port with which you must define the container.

I hope it is helpful, greetings

1 Like

Hi Ariel,

thanks for the answer!

Just to make clear I understood you correctly: In my case, the local port is 32782 and the container port is 80.
I access Gitlab via http://192.168.2.21:32782.

The way I understood you is I should set the external url to that (it is currently commented out) and the run the reconfigure and restart commands, right?

I will try out your suggestion later this afternoon.

OK, I’ve had the opportunity to try it. And the outcome was similar to before:
I tried it in a new container, with Port 32785:80. I set the external_url to ‘http://192.168.2.21:32785/’, reconfigured and restarted. All of this worked fine, seemingly. And the container restarted successfully, but I can’t connect to it.
When I enter the IP Address in the browser it just goes between the site didn’t send any data and the connection was reset.

Same thing after manually restarting the computer.

In the Terminal of the container it only says:

==> /var/log/gitlab/gitlab-rails/production.log <==                             
Started GET "/-/metrics" for 127.0.0.1 at 2018-08-29 21:26:07 +0000             
Processing by MetricsController#index as HTML                                   
Completed 200 OK in 2ms (Views: 0.5ms | ActiveRecord: 0.0ms)                    
                                                                            
==> /var/log/gitlab/gitlab-rails/production_json.log <==                        
{"method":"GET","path":"/-/metrics","format":"html","controller":"MetricsControl
ler","action":"index","status":200,"duration":4.28,"view":0.51,"db":0.0,"time":"
2018-08-29T21:26:07.703Z","params":[],"remote_ip":null,"user_id":null,"username"
:null}                                                                          
                                                                            
==> /var/log/gitlab/gitlab-monitor/current <==                                  
2018-08-29_21:26:11.53171 127.0.0.1 - - [29/Aug/2018:21:26:11 UTC] "GET /sidekiq
 HTTP/1.1" 200 13639                                                            
2018-08-29_21:26:11.53193 - -> /sidekiq                                         
2018-08-29_21:26:13.43017 127.0.0.1 - - [29/Aug/2018:21:26:13 UTC] "GET /databas
e HTTP/1.1" 200 63132                                                           
2018-08-29_21:26:13.43022 - -> /database                                        
2018-08-29_21:26:15.68017 127.0.0.1 - - [29/Aug/2018:21:26:15 UTC] "GET /process
 HTTP/1.1" 200 1364                                                             
2018-08-29_21:26:15.68022 - -> /process

I can’t make too much sense of that, though.

Do you have another suggestion?

In this case, you must recreate the container with the new port

ports:
    - "32782:32782"
1 Like

Can you please explain, why I have to recreate the container for this port?
Why is it 32782:32782 now and it was 80:90 before? Why would I be linking the 32782 port externally to the same internally? And what’s so special about port 90?

I’m sorry for all these questions, but I’d like to understand a bit more before I start modifying the container.

Thanks for your support so far!

I’m sorry, maybe this documentation is better explained

pre-configure-docker-container

Before recreating the container, make sure you have the volumes in the correct mount points or you can create a container2 and mount-point2 and make the adjustment to understand and then apply it in your installation

Regards,

1 Like

That minus the setting of external url, is exactly how I created the server. When I run it with setting the external url property, I can’t access gitlab at all. It starts up, and everything seems normal, but I get no response, when entering the IP in the browser.

I also still don’t understand, why I should link port 32782 to 32782. Gitlab is not normally listening on that port internally, is it? I’d understand if it was something like 32782:80…

The default port of gitlab is 80, but when you use the external_url clause, gitlab changes the ngnix port to which it is going to listen or resolve, it is not just an alias.

If you inside the container executes the command curl http://localhost, after having placed external_url ‘http://ip:32782’, it will not answer for port 80, you can try with the command curl http://localhost:32782

Regards,

2 Likes

Thanks a lot! So it makes sense, that the container booted correctly but I couldn’t access it. Due to my 32782:80 setting it was accessing port 80 internally while listening to 32782. This solved my issue.

To recap for those as inexperienced as me:
For my test I created a new container similar to the link, but with the exception of port 32782:80 that I set to 32782:32782.

sudo docker run --detach \
--hostname gitlab.example.com \
--env GITLAB_OMNIBUS_CONFIG="external_url 'http://192.168.2.21:32782/'" \
--publish 32781:443 --publish 32782:32782 --publish 32783:22 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest

I also tried to update the external_url in the gitlab.rb and then powering down the container to change the ports in the GUI, which also worked.

Thanks for your continued support!

1 Like

You are Welcome.

1 Like

Hi, barria.There is another way to solve this problem.You can run gitlab container with port mapping 32782:80,and change the external_url to ‘http://xxxx:32782’,in addition, adding nginx[‘listen_port’] = 80,nginx[‘listen_https’] = false int the gitlab.rb.This will also work fine.

perfect, thanks for sharing