Steps for installing Gitlab with Docker

  • 2020-12-09 01:08:07
  • OfStack

Gitlab profile

GitLab is a code hosting tool for Git. There is a free community version that allows you to build code hosting sites locally, and there is a paid enterprise version that allows you to host code online. The traditional approach is to manually download the Gitlab package and then set up the relevant runtime environment. But this is a very troublesome way, and if you want to change all the configuration of the machine, you have to start all over again. If any of you have learned Java, you remember the fear of configuring environment variables when you first learned Java, right? So a better approach is to use Docker, which is now very popular.

So what is Docker? This is a virtualization running tool, the main purpose is to package the software and the entire running environment, so that we do not need to configure the software to run quickly. Because Docker relies on certain features of the Linux kernel, Docker can only run on Linux. Docker on Windows is actually 1 virtual machine on. It seems that there is no good Chinese community in Docker at present. I only found this Docker Chinese community in Google. It looks ok.

Install docker

I'm using Archlinux, so the installation commands are as follows.

sudo pacman -S docker

If you are using another system, you will need to switch to the appropriate package management tool.

Once installed, take a look at the version of Docker.

sudo docker version

It should display something like the following. The Docker client version should be above 1.10.

 Version:  1.13.1
 API version: 1.26
 Go version: go1.7.5
 Git commit: 092cba3727
 Built:  Sun Feb 12 02:40:56 2017
 OS/Arch:  linux/amd64

 Version:  1.13.1
 API version: 1.26 (minimum version 1.12)
 Go version: go1.7.5
 Git commit: 092cba3727
 Built:  Sun Feb 12 02:40:56 2017
 OS/Arch:  linux/amd64
 Experimental: false

This completes the installation of Docker.

Use Aliyun to accelerate Docker

Docker's official mirror website is deployed on the external network, so it is slow to download in China. The best Docker acceleration service in China is Ali Cloud. Other alicloud images like the Maven image are also good.

First of all, you need to register an Aliyun account, and you may also need one more point of information. Then go to the container Hub service console with an accelerator in the middle. When we click on it, Aliyun will create a dedicated accelerator address for us.

Then you need to check the version of Docker client. If it is less than 1.10, you can only find the corresponding method according to your own system version. If it is greater than or equal to 1.10, the following configuration method can be used directly. The configuration method is simple in /etc/docker/daemon.json Add 1 section configuration in. If the file is not available, it is created.

 "registry-mirrors": ["<your accelerate address>"]

Then restart the Docker service.

sudo systemctl daemon-reload
sudo systemctl restart docker

Download Gitlab

Once the accelerator is configured, the download is quick. Simply execute the following command, and after a few moments, Docker will download Gitlab.

sudo docker pull gitlab/gitlab-ce:latest

Start the Gitlab

Start a default configuration of Gitlab with the following command. Replace hostname with localhost if we only use it in native testing. Use the extranet IP address if you need to make it accessible to external systems.

sudo docker run --detach \
 --hostname \
 --publish 443:443 --publish 80:80 --publish 22: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 \

The first startup may be slow, requiring a wait of about 1 minute. We can use sudo docker ps Command to view the current status of all Docker containers. When its state changes from starting to run time, it is successfully started. We use the IP address configured above directly (for example localhost ) can be accessed in the browser.

The first time you use it, you need to create a default administrator password. Just specify one. Then we need to register a regular user. It will be used much like a tool like Github.

Configuration Gitlab

When we just started Gitlab, we need to enter 1 password, which is the password of the administrator user. We use root as the username there, and then with the password we just set, we can log in to Gitlab as an administrator.

After logging in, click the gear icon in the upper right corner to enter the administrator page. We can set up a lot of things here. For example, by default you can only create 10 repositories per user, so you can change this. Click the gear on the right side of the administrator page, and then click Settings, and you will enter the system Settings. And then we go to Default projects limit1, and we set a small target for it, let's say 100 million, so it's an infinite warehouse. Of course, you can't create more projects if your hard drive is actually full.

If these configurations still don't meet your needs, you can configure Gitlab directly. First enter the Docker environment. We use the following command to enter bash in the Docker environment. gitlab is the Gitlab name you just specified.

sudo docker exec -it gitlab /bin/bash

We then move into the environment of Docker, which we can use as a standalone system. Then edit/etc gitlab/gitlab rb file, this is Gitlab global configuration file. All options can be configured here.

nano /etc/gitlab/gitlab.rb

I won't go into the detailed configuration method either, just look at the official documentation.

Update Gitlab

If you need to update the Gitlab version in the future, you first need to stop and delete the current instance of Gitlab.

sudo docker stop gitlab
sudo docker rm gitlab

Then pull in the latest version of Gitlab.

sudo docker version

Then run Gitlab with the last configuration. Don't worry about losing data. As long as your volume parameter is specified the same as last time, Gitlab will automatically read these configurations.

sudo docker version

Finally, look at the advantages of using Docker. It's still in Bash for Gitlab. Let's type the following commands in turn to see what happens.

sudo docker version

Barring accidents, the version of the corresponding software should be displayed. We see that Gitlab uses four open source software or operating environments: ruby, git, redis, and postgresql. If we manually install Gitlab, these software must also be installed and configured separately. This task is extremely difficult. And if you need to configure on more than one machine, the task load is even greater. But with Docker, it's not even necessary to know that any of these programs exist. You can create and run Gitlab with two simple commands. That's the beauty of Docker, so it's no wonder more companies are using it now.

There's a nice Docker tutorial that you can look at.

The resources

Related articles: