How To Deploy GitLab With Docker In 5 Seconds Or Less

Introduction

GitLab is a web-based Git repository management tool that helps teams to collaborate on code. Also, it provides a complete DevOps platform, from version control, code review, issue tracking, and CI/CD.

One of the key benefits of Gitlab is its versatility and flexibility because it can be hosted on-premise and can be easily customized to suit the needs of every team. Additionally, it has a wide range of features and integrations, making it a good choice for teams.

Using Docker, it is incredibly easy and fast to set up a GitLab instance. You can spin up a Gitlab instance in a single command, without worrying about manually installing and configuring dependencies.

This makes it a great choice for software developers who want to start with GitLab quickly and easily.

Deploy GitLab using Sameersbn Compose file

The first step to deploy GitLab is downloading the up-to-date version of the Compose file:

wget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml

Now, generate three at least 64 characters long random strings, open the Compose file, and use these strings for:

  • GITLAB_SECRETS_OTP_KEY_BASE: Used to encrypt 2FA secrets in the database. No user will be able to log in with 2FA if you lose this key
  • GITLAB_SECRETS_DB_KEY_BASE: Used for encrypting CI secrets and import credentials. If changed/lost you will not be able to use CI secrets anymore.
  • GITLAB_SECRETS_SECRET_KEY_BASE: Use to generate password reset links and standard auth features. You cannot reset passwords through emails this is changed/lost.

Start your GitLab instance

docker-compose up

Deploy GitLab Manually Using Docker Commands

Instead of downloading the up-to-date Compose file from Sameersbn, you can manually launch the GitLab container, a Redis container, and a PostgreSQL container with three simple steps.

Step 1: Start the PostgreSQL container

docker run --name gitlab-postgresql -d \
    --env 'DB_NAME=gitlabhq_production' \
    --env 'DB_USER=gitlab' --env 'DB_PASS=password' \
    --env 'DB_EXTENSION=pg_trgm,btree_gist' \
    --volume ./gitlab_postgresql:/var/lib/postgresql \
    sameersbn/postgresql:12-20200524

Step 2: Start the Redis container

docker run --name gitlab-redis -d \
    --volume ./gitlab_redis:/var/lib/redis \
    sameersbn/redis:latest

Step 3: Start the GitLab container

docker run --name gitlab -d \
    --link gitlab-postgresql:postgresql --link gitlab-redis:redisio \
    --publish 10022:22 --publish 10080:80 \
    --env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \
    --env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \
    --env 'GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string' \
    --env 'GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string' \
    --volume ./gitlab_data:/home/git/data \
    sameersbn/gitlab:15.10.0
πŸ’‘
Note: The docker commands use shared volumes (indicated through ./) that will be created in the directory the Docker run command is executed

Accessing Your GitLab Instance

After the GitLab application is started successfully (could take some minutes) you can switch to your browser, point it to http://localhost:10080, and set a password for the root user account.

Now, the GitLab application is ready for testing and you can start pushing your code to it!

Conclusion

Setting up a personal GitLab is no rocket science and can be done in less than 3 seconds (image download and start-up times not included).

Although this tutorial is for personal setup on your development machine, you can easily do this on any server to make the GitLab instance available for everyone.

If doing this, I would suggest using the Sameersbn Compose file and adding a Traefik Proxy in front of it to make it available over a public domain name instead of an IP.

The following tutorial covers all steps needed to set up a Traefik proxy that can be used to make GitLab accessible with a Hostname and secure the connection with an SSL certificate:

How to setup Traefik v2 with automatic Let’s Encrypt certificate resolver
Today it is really important to have SSL encrypted websites. This guide will show how easy it is to have an automatic SSL resolver built into your traefik load balancer.

I hope this article gave you a quick and neat overview of how to set up your personal instance of GitLab.

Do you have any questions regarding this tutorial? I would love to hear your thoughts and answer your questions. Please share everything in the comments.

Feel free to connect with me on Medium, LinkedIn, Twitter, and GitHub.

Thank you for reading, and happy coding! πŸ₯³ πŸ‘¨πŸ»β€πŸ’»