GitLab installation and configuration (Docker)


GitLab is an open source project for a warehouse management system. It uses Git as a code management tool and builds a web service on this basis.

1. Install GitLab under Docker

1. Pull the docker image of gitlab, redis, and postgresql

gitlab relies on redis and postgresql

docker pull sameersbn/redisdocker pull sameersbn/postgresqldocker pull gitlab/gitlab-ce:latest

2. Create a postgresql container

  • Database user name DB_USER: gitlab
  • Database password DB_PASS: password
  • Local and container mapping path: -v /home/root/opt/postgresql/data:/var/lib/postgresql
docker run --name postgresql -d --privileged=true -e 'DB_NAME=gitlabhq_production' -e 'DB_USER=gitlab' -e 'DB_PASS=password' -e 'DB_EXTENSION=pg_trgm' -v /home/root/opt/postgresql/data:/var/lib/postgresql sameersbn/postgresql

3. Create a redis container

Local and container mapping path: -v /home/root/opt/redis/data:/var/lib/redis

docker run --name redis -d --privileged=true -v /home/root/opt/redis/data:/var/lib/redis sameersbn/redis

4. Create a gitlab container

  • Specify the host address--hostname: 26
  • Port mapping between this machine and the container: -p 10022:22 -p 8899:80
  • Modify the value of the environment variable:
  • Port number: -e'GITLAB_PORT=8899' -e'GITLAB_SSH_PORT=10022'
  • Host address: -e'GITLAB_HOST= 26 '
  • Local and container mapping path: -v /home/root/opt/gitlab/data:/home/git/data gitlab/gitlab-ce
docker run --name gitlab -d --link postgresql:postgresql --link redis:redis --hostname -p 10022:22 -p 8899:80 -e 'GITLAB_PORT=8899' -e 'GITLAB_SSH_PORT=10022' -e 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' -e 'GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string' -e 'GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string' -e 'GITLAB_HOST=' -e 'SMTP_AUTHENTICATION=login' -v /home/root/opt/gitlab/data:/home/git/data gitlab/gitlab-ce

5. Browser access

1) Access address:

For the first visit, you need to wait for a while, the gitlab container startup and initialization are slow; after the startup is successful, as shown in the following figure;

If the error "Whoops, GitLab is taking too much time to respond." is reported when accessing , first check whether the system resources are insufficient, such as insufficient memory; if the resources are sufficient, normal access is possible.

2) Set a new password for the root user

Password: Aa123456 (the password must have 8 digits, including upper and lower case, otherwise the setting may fail, gitlab user password restriction: Minimum password length (number of characters))

3) Log in with root username

Login account name: root

Password: Aa123456

6. After restarting the virtual machine, start the gitlab command again

docker start postgresqldocker start redisdocker start gitlab

Two, create and configure GitLab new users

Assuming that you use your own QQ mailbox to send a registration success email to a newly registered user, you need to turn on the POP3/SMTP service of the QQ mailbox account;

If it is not configured, the new user cannot receive the registration email, cannot complete the password setting, and the new user cannot log in and use;

1. Configure GitLab's mail sending

1) First open the POP3/SMTP service of QQ mailbox

QQ mailbox-->Settings-->Accounts-->POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV service, click to enable POP3/SMTP service, the following prompt pops up, follow the prompts to send SMS;

After the SMS is successfully sent, click "I have sent", and the following screenshot will be displayed: save the authorization code information, and then configure it to the gitlab configuration file;

2) Modify the configuration file of gitlab: /etc/gitlab/gitlab.rb

Enter the docker container

docker exec -it gitlab /bin/bash

Modify the configuration file

vi /etc/gitlab/gitlab.rb
  • smtp_user_name: The account number modified to QQ mailbox
  • smtp_password: modified to the configured authorization code
  • gitlab_email_from: modify the account of QQ mailbox
  • Other configurations remain unchanged
gitlab_rails['smtp_enable'] = truegitlab_rails['smtp_address'] = ""gitlab_rails['smtp_port'] = 465gitlab_rails['smtp_user_name'] = "******"gitlab_rails['smtp_password'] = "授权码"gitlab_rails['smtp_domain'] = ""gitlab_rails['smtp_authentication'] = "login"gitlab_rails['smtp_enable_starttls_auto'] = truegitlab_rails['smtp_tls'] = truegitlab_rails['gitlab_email_from'] = '******'

Execute the following commands in the gitlab container to make the configuration effective

gitlab-ctl reconfigure

Exit the gitlab container, execute the command to restart the gitlab container

docker restart gitlab

2. Create a new GitLab user

1) After gitlab starts successfully, visit

Log in with root/Aa123456

Click the wrench 🔧 to create a new user (you must enter a valid mailbox, otherwise the new user will not receive the successful registration email, and the account password cannot be reset, and the gitlab will not be able to log in);

After the new user is successfully created, the new user will receive the following email, click click here to reset the user password, after the reset is successful, you can visit gitlab

If you can’t open the page by clicking click here in the email, it ’s because the default port of gitlab built by yourself has been modified. Just add the port number 8899 after the access address to access;

3. Configure the SSH Keys of the new user

1) Download and install Git first

Download address:

This article uses the Windows version: 2.31.1

Click Git-2.31.1-64-bit.exe to install;

2) Enter the command in the Git Bash window and press Enter all the way to generate the key

ssh-keygen -t rsa -C "[email protected]"

3) Open the public key with Notepad and copy

Public key directory: C:\Users\user name\.ssh\

4) Add public key

Log in to the GitLab website, in the upper right corner of the profile picture -> Preferences -> SSH Keys, and add the copied text. After adding successfully, as shown below:

Three, create a new GitLab code warehouse

Projects-->Create blank project

Follow the prompts and execute the following commands locally to set the user name and email address for submitting the code

Git global setup:

git config --global "test"git config --global "[email protected]"

Create a new repository or Push an existing folder: you can create a new empty code repository, and then submit the local code to the code repository; you can also directly initialize the local project git and then push it to the gitlab server to create it A code repository;

The connection method used here is HTTP, and SSH is not used, because when pushing, the current system user will be used as the user name to connect to the gitlab server by default (the new gitlab user created in this article is test, and the system login user is XXX, which is inconsistent ), if the login user name on gitlab is inconsistent with the local user name, after entering the password, the login will fail, resulting in the inability to operate the remote code library;

Create a new repository execute the following command to create an empty code repository;

git clone shoppingtouch README.mdgit add README.mdgit commit -m "add README"git push -u origin master

Push an existing folder execute the following command to push the local project to the gitlab server to create a code repository;

cd existing_foldergit initgit remote add origin add .git commit -m "Initial commit"git push -u origin master

Screenshot of actual local command operation:

Screenshot after the code warehouse is successfully created: