Featured image of post Guide to installing Gitlab on your VPS server using Docker

Guide to installing Gitlab on your VPS server using Docker

Prerequisites

  1. VPS Server: You need access to a VPS server, either self-managed or from a hosting provider.
  2. Docker and Docker Compose: Ensure Docker and Docker Compose are installed on your server.

Prepare the Docker Compose File

Create a docker-compose.yml file for GitLab. This file defines the GitLab service, configurations, and volumes.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  version: '3'
  services:
    gitlab:
      image: 'gitlab/gitlab-ce:latest' 
      restart: always
      hostname: 'your-vps-ip'  # Hostname for the GitLab instance
      environment:  # Environment variables for GitLab
        GITLAB_OMNIBUS_CONFIG: |  # GitLab Omnibus configuration
          external_url 'http://your-vps-ip:40150'  # External URL for GitLab
          gitlab_rails['gitlab_shell_ssh_port'] = 40170  # SSH port for GitLab

      ports:  # Port mapping for the container
        - '40150:40150'  # HTTP port mapping
        - '40160:40160'  # HTTPS port mapping
        - '40170:40170'  # SSH port mapping
      volumes:
        - '/srv/gitlab/config:/etc/gitlab'  # GitLab configuration
        - '/srv/gitlab/logs:/var/log/gitlab'  # GitLab logs
        - '/srv/gitlab/data:/var/opt/gitlab'  # GitLab data
      networks:
        - gitlab_network  # Attach to the gitlab_network
  networks:
    gitlab_network:  # Network for GitLab containers
      driver: bridge  # Bridge network driver

Replace your-vps-ip with your VPS server’s IP address.

Create Necessary Directories

1
sudo mkdir -p /srv/gitlab/config /srv/gitlab/logs /srv/gitlab/data

Start GitLab Docker Container

1
docker-compose up -d

This command downloads the GitLab Docker image (if not already downloaded) and starts the GitLab service in detached mode. Please note that GitLab will take some time to initialize, around 15 minutes.

Configure GitLab

After starting the container, you can access GitLab via http://your-vps-ip:40150.

Getting root password

Run the following command to list all running containers and find the GitLab container ID:

1
docker ps -a

Located to the Gitlab container ID

Gitlab

Using the GitLab container ID, run the following command to get the root password:

1
sudo docker exec -it containerID grep 'Password:' /etc/gitlab/initial_root_password

After getting the password, go back to the GitLab login page and sign in with username “root”.

Additional Configuration (Optional)

  • Custom Domain: If you have a domain, configure DNS settings to point to your VPS IP address. Update the external_url in the docker-compose.yml file to match your domain, e.g., https://gitlab.example.com.

  • HTTPS (SSL/TLS) Setup: For securing your GitLab instance with HTTPS, it’s recommended to use a reverse proxy like Nginx or set up a Let’s Encrypt certificate. Refer to the previous response on how to set up HTTPS with Nginx and Let’s Encrypt.

Additional Notes:

  • Ensure your VPS firewall allows traffic the ports that you are using in the docker-compose file.
  • Regularly update GitLab and Docker to maintain security.
  • Always keep your server and GitLab instance up to date with the latest security patches.

By following these steps, you’ll have GitLab up and running on your VPS server using Docker. Remember, security, backup, and maintenance are critical aspects of managing any server-based application.