GitLab is a free and open-source application used to host Git repositories. It is a web-based repository manager and fully-featured platform for accelerated software development. It comes with a lot of built-in tools that help you to represent every task in your development workflow. GitLab is availabe in three editions, GitLab Community Edition, Enterprise Edition, and a GitLab-hosted version. It comes with a user-friendly web interface that allows your team to collaborate on coding, testing, and deploying applications.
In this tutorial, we will show you how to install GitLab CE with Docker on Ubuntu 20.04 server.
Requirements
- A server running Ubuntu 20.04 with 4GB RAM.
- A valid domain name pointed with your server IP. In this tutorial, we will use https://linuxbuz.com domain.
- A root password is configured in your server
Getting Started
Before starting, update your system packages to the latest version with the following command:
# apt update && apt upgrade -y
Next, install some required dependencies by running the following command:
# apt install apt-transport-https ca-certificates curl software-properties-common -y
Once all the packages are installed, you can proceed to install Docker CE.
Install Docker and Docker Compose
By default, the latest version of Docker is not available in the Ubuntu default repository. So you will need to add the Docker repository in your system. You can add it with the following command:
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
Once the repository is added, install the Docker and Docker Compose using the following command:
# apt install docker-ce docker-compose -y
Once the docker has been installed, you can verify the installed version of Docker with the following command:
# docker info
You should get the following output:
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.12
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.4.0-29-generic
Operating System: Ubuntu 20.04 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.844GiB
Name: ubuntu2004
ID: BVY4:ELUS:PEOF:UMYR:NBNY:YYNL:OYDN:M5XW:H4Y7:CFLK:ZOUX:AIEE
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Set Up GitLab Directory Structure
First, you will need to set up a directory structure for GitLab.
You can create required directories with the following command:
# mkdir ~/gitlab
# mkdir -p /mnt/gitlab/{config/ssl,logs,data}
Next, change the directory to ~/gitlab and create an environment file to define the GitLab home directory:
# cd ~/gitlab
# nano .env
Add the following line:
GITLAB_HOME=/mnt/gitlab
Next, create a yml file for GitLab:
# nano docker-compose.yml
Add the following lines:
web:
image: 'gitlab/gitlab-ce:latest'
restart: always
hostname: 'gitlab.linuxbuz.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
# Add any other gitlab.rb configuration here, each on its own line
external_url 'https://gitlab.linuxbuz.com'
gitlab_rails['gitlab_shell_ssh_port'] = 2224
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/privkey.pem"
nginx['ssl_dhparam'] = "/etc/gitlab/ssl/dhparams.pem"
ports:
- '80:80'
- '443:443'
- '2224:22'
volumes:
- '${GITLAB_HOME}/config:/etc/gitlab'
- '${GITLAB_HOME}/logs:/var/log/gitlab'
- '${GITLAB_HOME}/data:/var/opt/gitlab'
- '${GITLAB_HOME}/config/ssl:/etc/gitlab/ssl'
Save and close the file when you are finished.
Generate Let's Encrypt SSL
Next, you will need to generate Let's Encrypt SSL to secure your GitLab instance. First, install the Certbot client with the following command:
# apt install certbot -y
Next, generate the Let's Encrypt SSL with the following command:
# certbot certonly --rsa-key-size 2048 --standalone --agree-tos --no-eff-email --email my@email.com -d gitlab.linuxbuz.com
Once the certificate has been generated, you should get the following output:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for gitlab.linuxbuz.com
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/gitlab.linuxbuz.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/gitlab.linuxbuz.com/privkey.pem
Your cert will expire on 2020-12-15. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
Next, copy the generated certificate to the GitLab directory with the following output:
# cp /etc/letsencrypt/live/gitlab.linuxbuz.com/fullchain.pem /mnt/gitlab/config/ssl/
# cp /etc/letsencrypt/live/gitlab.linuxbuz.com/privkey.pem /mnt/gitlab/config/ssl/
Next, generate the DHPARAM certificate with the following command:
# openssl dhparam -out /mnt/gitlab/config/ssl/dhparams.pem 2048
Create a GitLab Container
Next, you will need to pull the GitLab CE image and build the container.
First, change the directory to ~/gitlab and build the container with the following command:
# cd ~/gitlab
# docker-compose up -d
You should get the following output:
Pulling web (gitlab/gitlab-ce:latest)...
latest: Pulling from gitlab/gitlab-ce
8e097b52bfb8: Pull complete
a613a9b4553c: Pull complete
acc000f01536: Pull complete
73eef93b7466: Pull complete
dbbf6a69d17d: Pull complete
8926eb0425bd: Pull complete
132637f1cbe1: Pull complete
d343616ff790: Pull complete
819cb051898b: Pull complete
d434b0b6371c: Pull complete
Digest: sha256:d8147f73fafdf5bef6359483a046f3d947f532a6c015dc197bbd4de9d6e61a33
Status: Downloaded newer image for gitlab/gitlab-ce:latest
Creating gitlab_web_1 ... done
Next, verify the GitLab container with the following command:
# docker-compose ps
You should see the following output:
Name Command State Ports
-----------------------------------------------------------------------------------------------------------------------
gitlab_web_1 /assets/wrapper Up (health: starting) 0.0.0.0:2224->22/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp
Access GitLab Web Interface
Now, open your web browser and access the GitLab web interface using the URL https://gitlab.linuxbuz.com. You should see the following screen:
Set your admin password and click on the Change your password button. You should see the following screen:
Now, provide username as a root and the password which you set in the previous step, and click on the Sign in button. You should see the GitLab CE dashboard in the following screen:
Conclusion
Congratulations! you have successfully installed GitLab CE with Docker on Ubuntu 20.04 server.
You can now explore the GitLab CE and create your first project from the web-based interface.
Note
Remember that you'll have to wait some minutes until Docker deploys.