Objective: Build a simple DevOps lab using Docker Compose to run both SonarQube and GitLab locally on Kali Linux.
This setup is perfect for developers, DevSecOps learners, or anyone working in a local security-focused environment like Kali.
Install Docker & Docker Compose on Kali Linux
sudo apt update && sudo apt install -y docker.io docker-compose
sudo systemctl enable --now docker
And after installation is done you can check version by runing this:
sudo docker version
or
sudo docker compose version
Create a Docker Project Folder
mkdir Homework003_SonarQube_Gitlab_Docker
touch docker-compose.yml
you can use ls command to see the file or folder you just create.
Install SonarQube with Docker Compose
Use "docker-compose.yml" for SonarQube
Replace the contents with:
version: "3.9"
services:
sonarqube:
image: sonarqube:10-community
container_name: sonarqube
restart: unless-stopped
ports:
- "9000:9000"
environment:
# JVM memory settings to avoid out-of-memory errors
SONAR_JAVA_OPTS: "-Xms512m -Xmx1024m"
deploy:
resources:
limits:
memory: 2048m # optional: only works with Docker Swarm
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_logs:/opt/sonarqube/logs
- sonarqube_extensions:/opt/sonarqube/extensions
volumes:
sonarqube_data:
sonarqube_logs:
sonarqube_extensions:
Run SonarQube
sudo docker compose up -d sonarqube
You can check the running container by:
sudo docker ps
Once the container is running, you'll see that SonarQube is active on port 9000. You can now open your browser and navigate to:
http://localhost:9000
After entering the URL, you'll be greeted by the SonarQube login page:
Login credentials:
- User: admin
- Password: admin
After logging in for the first time, SonarQube will prompt you to change your default password. Simply enter a new, secure password to continue.
Once you've successfully updated your password, you'll be redirected to the SonarQube dashboard. From here, you can begin setting up your projects - either by connecting to popular platforms like GitHub or GitLab, or by creating one manually.
Install Gitlab with Docker Compose
In the same project folder, open your existing docker-compose.yml:
and Append the following GitLab service below the existing sonarqube config:
gitlab:
image: gitlab/gitlab-ce:17.0.1-ce.0
container_name: gitlab
restart: unless-stopped
hostname: gitlab.local
shm_size: "256m"
ports:
- "8080:80" # Web interface (external → internal)
- "8443:443" # HTTPS (optional if not needed)
- "2222:22" # SSH for repo clone
volumes:
- gitlab_config:/etc/gitlab
- gitlab_logs:/var/log/gitlab
- gitlab_data:/var/opt/gitlab
volumes:
gitlab_config:
gitlab_logs:
gitlab_data:
when merge everything together, it should look like this:
version: "3.9"
services:
sonarqube:
image: sonarqube:10-community
container_name: sonarqube
restart: unless-stopped
ports:
- "9000:9000"
environment:
# JVM memory settings to avoid out-of-memory errors
SONAR_JAVA_OPTS: "-Xms512m -Xmx1024m"
deploy:
resources:
limits:
memory: 2048m # optional: only works with Docker Swarm
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_logs:/opt/sonarqube/logs
- sonarqube_extensions:/opt/sonarqube/extensions
gitlab:
image: gitlab/gitlab-ce:17.0.1-ce.0
container_name: gitlab
restart: unless-stopped
hostname: gitlab.local
shm_size: "256m"
ports:
- "8080:80" # GitLab web UI
- "8443:443" # HTTPS (optional)
- "2222:22" # SSH for cloning repos
volumes:
- gitlab_config:/etc/gitlab
- gitlab_logs:/var/log/gitlab
- gitlab_data:/var/opt/gitlab
volumes:
sonarqube_data:
sonarqube_logs:
sonarqube_extensions:
gitlab_config:
gitlab_logs:
gitlab_data:
Then run this:
sudo docker compose up -d gitlab
Access GitLab
Add hostname to etc/hosts
sudo nano /etc/hosts
Add this line at the bottom
127.0.0.1 gitlab.local
Open browser:
http://gitlab.local:8080
GitLab will ask you to set a new root password. After that, log in as:
Username: root
Password: you need to run this command to get password
sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
Top comments (0)