Install GitLab on Docker: Step-by-Step Guide for DevOps and IT Operations
Introduction
GitLab is a powerful DevOps platform offering version control, CI/CD, issue tracking, and more. Running GitLab inside Docker simplifies setup, improves portability, and provides better resource management.
This article guides you through installing GitLab on Docker step by step — perfect for developers, system administrators, and IT operations professionals.
🚀 Why Choose GitLab on Docker?
- Portability & isolation: Containers make GitLab easy to move and independent from the host system.
- Simplified upgrades: Swap images and upgrade seamlessly.
- Quick replication: Clone environments for testing or staging in minutes.
- Efficient for Ops teams: Docker and Compose simplify automation and CI/CD integration.
🧱 Prerequisites
Before starting, ensure you have:
- A Linux host (Ubuntu, CentOS, etc.) with sudo access
- Docker Engine and Docker Compose installed
- Minimum 4 GB RAM for smooth performance
- Persistent storage for config, logs, and data
- Optional: Domain name + SSL (Let’s Encrypt recommended)
⚙️ Step 1 – Install Docker and Docker Compose
Run these commands on Ubuntu 22.04:
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
sudo systemctl enable docker
sudo systemctl start docker
For Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Check installation:
docker --version
docker-compose --version
docker run hello-world
📂 Step 2 – Create Directories for GitLab Data
Set up directories to store persistent data:
sudo mkdir -p /srv/gitlab/{config,logs,data}
sudo chown -R 1000:1000 /srv/gitlab
export GITLAB_HOME=/srv/gitlab
These ensure your configuration and repositories survive container restarts or upgrades.
🐳 Step 3 – Pull GitLab Docker Image
Download the Community Edition (CE):
docker pull gitlab/gitlab-ce:latest
Or Enterprise Edition (EE):
docker pull gitlab/gitlab-ee:latest
Pin to a specific version for production stability.
📄 Step 4 – Create Docker Compose File
Create a docker-compose.yml file in /srv/gitlab:
version: '3.7'
services:
gitlab:
image: 'gitlab/gitlab-ce:latest'
container_name: gitlab
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://gitlab.example.com'
ports:
- '80:80'
- '443:443'
- '22:22'
volumes:
- '$GITLAB_HOME/config:/etc/gitlab'
- '$GITLAB_HOME/logs:/var/log/gitlab'
- '$GITLAB_HOME/data:/var/opt/gitlab'
shm_size: '256m'
Optional custom ports:
ports:
- '8080:80'
- '8443:443'
- '2222:22'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.example.com:8080'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
▶️ Step 5 – Start GitLab Container
Start your GitLab instance:
docker-compose up -d
Monitor progress:
docker-compose ps
docker logs -f gitlab
Initial startup may take a few minutes — patience is key.
🔐 Step 6 – Access GitLab Dashboard
Once the container is ready:
- Open
https://gitlab.example.com - Set the root password when prompted
- Login as
rootand start configuring your projects
To retrieve the password manually:
docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
🧭 Step 7 – Configuration Tips & Best Practices
- Backups: Regularly back up
/srv/gitlab/data,/config, and/logs - Upgrades: Pull new image →
docker-compose up -d - Performance: Minimum 4 GB RAM; use SSD storage
- Security: Enable HTTPS with Let’s Encrypt or Nginx reverse proxy
- Monitoring: Use
docker logsorgitlab-ctl status - CI/CD Optimization: Use separate runners for large jobs
🩻 Troubleshooting Common Issues
| Issue | Solution |
|---|---|
| Port conflict (80/443) | Change host ports in docker-compose.yml |
| 502 Bad Gateway | Wait for GitLab initialization to finish |
| SSH clone errors | Adjust gitlab_shell_ssh_port to match mapped port |
| Lost data after restart | Ensure volumes are correctly mapped |
| Unhealthy container | Check file permissions or SELinux context |
⚡ Why Docker Setup is Great for IT Operations
- Predictable and repeatable deployments
- Full control of your GitLab instance
- Persistent data volumes ensure reliability
- Easier backups and maintenance
- Scalable architecture—ready for Kubernetes or cloud migration
✅ Conclusion
By following this step-by-step guide, you’ve learned how to install GitLab on Docker effectively.
This setup gives you a self-hosted, flexible, and maintainable DevOps environment suitable for individuals and organizations alike.
💡 Once deployed, explore GitLab CI/CD and automated backups to fully unlock your DevOps potential.