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
    version: '3'

    services:
    gitlab:
        image: 'gitlab/gitlab-ce:latest'
        restart: always
        ports:
        - '80:80'
        - '443:443'
        - '22:22'
        environment:
        GITLAB_OMNIBUS_CONFIG: |
            external_url 'http://your-vps-ip'            
        volumes:
        - '/srv/gitlab/config:/etc/gitlab'
        - '/srv/gitlab/logs:/var/log/gitlab'
        - '/srv/gitlab/data:/var/opt/gitlab'

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.

Configure GitLab

After starting the container, you can access GitLab via http://your-vps-ip. Follow the on-screen instructions to set up the root password and configure your GitLab instance.

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 on ports 80, 443, and 22.
  • 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.