← Back to list

How to Install SonarQube Using Docker on EC2 (Ubuntu 24.04)

Maintaining high code quality is critical in modern DevOps practices. SonarQube helps teams continuously inspect code quality, detect bugs…

Rajesh Thakur · 2025-12-19 06:57 · 0 claps · 2.3 min read
#sonarqube #sonar #aws #devops #security
Open on Medium ↗
Wiki topics: ☁️ · DevOps & Cloud 🔓 · Open Source

How to Install SonarQube Using Docker on EC2 (Ubuntu 24.04)

Maintaining high code quality is critical in modern DevOps practices. SonarQube helps teams continuously inspect code quality, detect bugs, vulnerabilities, and code smells before they reach production.

In this article, we’ll install SonarQube using Docker on a separate EC2 instance running Ubuntu 24.04, which is a recommended approach when integrating it with Jenkins or other CI/CD tools.

🧩 Why Run SonarQube on a Separate EC2?

  • Better performance isolation
  • Improved security
  • Easier scaling and maintenance
  • Clean separation between CI and code-quality services

✅ Prerequisites

Before starting, make sure you have:

  • An EC2 instance (Ubuntu 24.04)
  • Minimum 2 vCPU & 4 GB RAM (recommended)
  • SSH access with sudo privileges
  • Docker installed
  • Port 9000 allowed in the EC2 Security Group

🏗️ Architecture Overview

Developer → GitHub → Jenkins (EC2-1) → SonarQube (EC2-2) → Quality Gate

🔄 Step 1: Update the System

Start by updating your instance to avoid dependency issues.

sudo apt update && sudo apt upgrade -y

🐳 Step 2: Install Docker

Install Docker from Ubuntu’s official repository.

sudo apt install -y docker.io

Start and enable Docker:

sudo systemctl start docker
sudo systemctl enable docker

Verify the installation:

docker --version

👤 Step 3: Run Docker Without Sudo (Optional)

To avoid using sudo with Docker commands:

sudo usermod -aG docker $USER
newgrp docker

🧠 Step 4: Configure Kernel Parameters (Mandatory)

SonarQube uses Elasticsearch, which requires higher kernel limits.

sudo sysctl -w vm.max_map_count=262144
sudo sysctl -w fs.file-max=65536

Make these changes permanent:

echo "vm.max_map_count=262144" | sudo tee -a /etc/sysctl.conf
echo "fs.file-max=65536" | sudo tee -a /etc/sysctl.conf

Apply the configuration:

sudo sysctl -p

📦 Step 5: Pull SonarQube Docker Image (LTS)

Always use the LTS version for stability.

docker pull sonarqube:lts

▶️ Step 6: Run SonarQube Container

Start SonarQube as a Docker container:

docker run -d \
  --name sonarqube \
  -p 9000:9000 \
  --restart always \
  sonarqube:lts

Check container status:

docker ps

🔥 Step 7: Open Required Port

If UFW is enabled:

sudo ufw allow 9000
sudo ufw reload

AWS Security Group

Ensure the EC2 Security Group allows:

  • Inbound TCP 9000
  • Source: Jenkins EC2 IP (recommended) or 0.0.0.0/0 (temporary)

🌐 Step 8: Access SonarQube Web Interface

Open your browser and navigate to:

http://<EC2_PUBLIC_IP>:9000

Default Login Credentials

Username: admin
Password: admin

You’ll be prompted to change the password after logging in.

🎉 Installation Successful!

SonarQube is now up and running on Ubuntu 24.04 using Docker on a separate EC2 instance.

🔗 Integrating SonarQube with Jenkins

To connect Jenkins with SonarQube:

  1. Go to SonarQube → My Account → Security
  2. Generate a token
  3. In Jenkins:
  • Navigate to Manage Jenkins → System
  • Configure SonarQube Servers
  • Add the SonarQube URL and token

Use the private IP of the SonarQube EC2 for better security.

🔒 Production Best Practices

  • Use PostgreSQL instead of the embedded database
  • Restrict port 9000 to Jenkins IP only
  • Place SonarQube behind Nginx + HTTPS
  • Back up Docker volumes regularly
  • Rotate authentication tokens

❌ Common Issues & Fixes

IssueSolutionSonarQube stuck on startupIncrease vm.max_map_countPort 9000 not accessibleCheck Security Group & UFWContainer exits unexpectedlyCheck logs

docker logs sonarqube

🚀 Next Steps

  • Configure Sonar Scanner in Jenkins
  • Add SonarQube stage in Jenkins pipeline
  • Enable Quality Gates
  • Integrate with GitHub Pull Requests

✍️ Author

Rajesh Thakur DevOps Engineer | AWS | Docker | Jenkins | SonarQube

🏷️ Medium Tags

#DevOps #SonarQube #Docker #AWS #EC2 #Ubuntu #CICD

메타데이터
post_id
a7d424c8d0dd
slug
how-to-install-sonarqube-using-docker-on-ec2-ubuntu-24-04-a7d424c8d0dd
url
https://medium.com/@thakurrajesh22293/how-to-install-sonarqube-using-docker-on-ec2-ubuntu-24-04-a7d424c8d0dd
canonical_url
https://medium.com/@thakurrajesh22293/how-to-install-sonarqube-using-docker-on-ec2-ubuntu-24-04-a7d424c8d0dd
author_url
https://medium.com/@thakurrajesh22293
status
ok
fetched_at
2026-07-14 02:31:40