Gitlab CE Basic Setup
Gitlab CE Basic Setup
Prerequisites
Before starting, ensure you have:
- Virtual Machine (VM) with minimum 4GB RAM
- Public IP address (check yours here)
- Domain configured in Cloudflare with DNS management access
Gitlab Setup Walkthrough
Optional: Install Docker & Docker Compose
For Ubuntu-based systems, use these commands:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
# Install Docker components:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Verify installation:
1
docker -v && docker compose version
1. Configure GitLab CE
Docker Compose Configuration
Create docker-compose.yml with these settings:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
services:
gitlab:
image: 'gitlab/gitlab-ce:${GITLAB_IMAGE_TAG}'
restart: unless-stopped
hostname: ${GIT_DOMAIN}
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://${GIT_DOMAIN}'
nginx['client_max_body_size'] = '2G'
nginx['listen_port'] = 80
nginx['listen_https'] = false
registry_external_url 'http://${RIGISTRY_SUB}.${DOMAIN_ADDRESS}'
gitlab_rails['gitlab_shell_ssh_port'] = 2224
letsencrypt['enable'] = false
# Disable unused services
prometheus['enable'] = false
alertmanager['enable'] = false
pgbouncer_exporter['enable'] = false
puma['exporter_enabled'] = false
gitlab_exporter['enable'] = false
node_exporter['enable'] = false
sidekiq['metrics_enabled'] = false
redis_exporter['enable'] = false
postgres_exporter['enable'] = false
ports:
- '80:80'
- '2224:22'
volumes:
- './config:/etc/gitlab'
- './logs:/var/log/gitlab'
- './data:/var/opt/gitlab'
shm_size: '256m'
Environment variables (save as .env):
1
2
3
4
5
6
7
8
# Gitlab Domain
DOMAIN_ADDRESS=example.com
GIT_SUB=gitlab
RIGISTRY_SUB=registry
GIT_DOMAIN=${GIT_SUB}.${DOMAIN_ADDRESS}
# GitLab image tag
GITLAB_IMAGE_TAG=17.8.1-ce.0
Start the container:
1
sudo docker compose up -d
2. Initial GitLab Setup
- Access web UI at
http://your-vm-ip - Retrieve root password:
1
sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
- Login with username
rootand obtained password
3. Network Configuration
Port Forwarding
- On your router, forward TCP ports 80 and 2224 to your VM’s local IP
DNS Setup
- In Cloudflare, create
Arecord:- Name:
gitlab.your-domain.com - Value: Your public IP
- Name:
- In Nginx Proxy Manager:
- Create proxy host with:
- Domain:
gitlab.your-domain.com - Scheme:
http - Forward to:
[VM-local-IP]:80- Apply SSL certificate in SSL tab
4. Post-Install Configuration
- Disable public sign-ups:
- Admin Area > Settings > General > Sign-up restrictions
- Create user account:
- Admin Area > Users > New user
- Set password via user profile
- SSH Key Setup:
- Profile > Preferences > SSH Keys
- Add public SSH key
5. Repository Management
- Create group/project:
- Groups > New group
- Projects > New project
- Clone repository:
1
git clone ssh://git@gitlab.your-domain.com:2224/your-group/your-project.git
- Make changes and push:
1
2
3
git add .
git commit -m "First commit"
git push origin main
Troubleshooting Tips
- Check container logs:
docker logs gitlab - Reset admin password:
docker exec -it gitlab gitlab-rake "gitlab:password:reset[root]" - Clean container data:
docker compose down -v
🎉 Congratulations! Your self-hosted GitLab instance is now ready for development!
Useful References
This post is licensed under
CC BY 4.0
by the author.