SoFunction
Updated on 2025-03-10

How to solve the problem of 22 ports being occupied after Docker starts gitlab

Preface

I have been studying the issue of Docker starting gitlab in the past two days. The email issue has come to an end for the time being. When I really started using gitlab cloning, I found that the 22 port was occupied and could not be started before. I used the 2022 port to make a mapping, but the cloning address provided on the gitab interface is similar.git@:games/, no shadow of port 2022, executegit clone git@:games/It is indeed not downloadable, so I searched for a circle of solutions and summarized them here to facilitate future search.

Docker startup parameters

docker run --detach \
  --hostname  \
  --publish 443:443 --publish 80:80 --publish 2022:22 \
  --name gitlab \
  --restart always \
  --volume /export/docker/gitlab/config:/etc/gitlab \
  --volume /export/docker/gitlab/logs:/var/log/gitlab \
  --volume /export/docker/gitlab/data:/var/opt/gitlab \
  /z5z/gitlab-ce:latest

This was beforearticleAs mentioned in this article, because ports 80 and 443 are normally available, all downloads using HTTPgit clone /games/It is normal, and the SSH download method is not downloaded because the default port is modified, even if I dogit clone git@:2022/games/The port cannot be cloned normally even if it is added.

A relatively stupid method is to close the SSH service or change the SSH service of the host to a port, but this is a remote server, which is generally accessed through the SSH protocol. It is not realistic to close it, and it is feasible to modify the port. However, there were multiple tasks running on this machine before, which means that many service scripts have to be modified, so it is not a good method. You cannot change all the original old scripts just by adding a new service. Try it many times and finally find a method that can be received.

Solution

  • Enter the gitlab containerdocker exec -it gitlab

  • Modify the configuration file/etc/gitlab/Content in

    gitlab_rails['gitlab_shell_ssh_port'] = 2022
    

    Note that this setting only changes the display information of GitLab and will not change the SSH service port in the GitLab container.

  • implementgitlab-ctl reconfigureJust

    After the modification is executed, check the gitlab download address again and find that it has been changed.ssh://git@:2022/games/, not only added the port number, but also added it in front of itssh://No wonder I can't use the port number myself. I have also found relevant explanations for this:

The SSH cloning address provided by GitLab (such as git@:2022/games/) is a simplified format that does not specify the protocol prefix ssh:// and port number. This is because by default, Git uses the SSH protocol to connect and clone and operate repositories via port 22 by default. Therefore, this simplified format omits the ssh:// prefix and port number

For standard ports (22), the address of the simplified format is valid because the Git client will use the SSH protocol by default and connect to port 22. However, when your SSH port is different from 22 (such as when using 2022), the default simplified format of Git is not applicable. You need to explicitly specify the port number or configure SSH, that is, write it as ssh://git@:2022/games/

Summarize

  • Use docker to start gitlab to encounter 22 port occupation, you can choose other port mapping.--publish 2022:22
  • After modifying the mapping port, in order to make the download address display correctly, you need to modify the gitlab configuration file.gitlab_rails['gitlab_shell_ssh_port'] = 2022
  • git@:games/is a simplified form of the ssh protocol, the complete address should bessh://git@:22/games/

This is the article about how to solve the problem of how to use the 22 port after Docker starts gitlab. For more related Docker 22 ports, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!