SonarQube Docker Installation
Docker packages SonarQube and everything it needs into a ready-to-run container. You skip manual Java setup, avoid version clashes, and remove the whole installation with one command. This method suits learners, test servers, and small teams.
Why Choose Docker
- Setup takes minutes instead of an afternoon.
- The same container runs on Windows, macOS, and Linux.
- Upgrades mean pulling a newer image.
- Cleanup leaves no leftover files on your computer.
How the Pieces Fit
Your Computer
┌────────────────────────────────────────────────┐
│ Docker │
│ ┌──────────────────┐ ┌─────────────────┐ │
│ │ sonarqube │────►│ postgres │ │
│ │ container │ │ container │ │
│ │ port 9000 │ │ (stores results)│ │
│ └────────┬─────────┘ └────────┬────────┘ │
│ │ volumes │ volume │
│ data / extensions / logs database files │
└───────────┼────────────────────────┼───────────┘
▼ ▼
Browser: http://localhost:9000
Volumes keep your data safe when a container stops or updates.
Method 1: Quick Trial With One Command
This command starts the Community Build with its built-in test database.
docker run -d --name sonarqube -p 9000:9000 sonarqube:community
Open http://localhost:9000 after a minute. Log in with the username admin and the password admin. SonarQube asks you to choose a new password right away.
Use this method for learning only. The built-in database does not support upgrades or production work.
Method 2: Docker Compose With PostgreSQL
Create a file named docker-compose.yml with this content.
services:
sonarqube:
image: sonarqube:community
depends_on:
- db
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: change_this_password
ports:
- "9000:9000"
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
db:
image: postgres:17
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: change_this_password
POSTGRES_DB: sonar
volumes:
- postgresql_data:/var/lib/postgresql/data
volumes:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:
postgresql_data:
Start everything with this command.
docker compose up -d
Understanding the File
Image
The tag sonarqube:community pulls the free Community Build. Developer and Enterprise images use the tags developer and enterprise.
Environment
The three JDBC variables tell SonarQube where the database lives and how to log in. Replace the sample password with a strong one.
Volumes
Three SonarQube folders keep indexes, plugins, and logs. A fourth volume keeps the database files. Deleting a container leaves volumes untouched.
Linux Host Setting
The search component needs a higher memory-map limit on Linux. Run this command on the Docker host before you start the container.
sudo sysctl -w vm.max_map_count=524288
Docker Desktop on Windows and macOS usually handles this limit automatically.
Useful Daily Commands
| Task | Command |
|---|---|
| Check running containers | docker ps |
| Read live logs | docker compose logs -f sonarqube |
| Stop the stack | docker compose stop |
| Remove containers, keep data | docker compose down |
Troubleshooting
- A container that exits at once usually signals the memory-map limit on Linux.
- A blank page during the first minute is normal startup time.
- A port conflict means another program already uses 9000. Change the left side of the port mapping, for example 9100:9000.
Why Persistent Volumes Matter
A container behaves like a rented room. When you leave, the room resets to its original state. Any file written inside the container disappears when you remove it. Volumes act like a personal storage box kept outside the room. SonarQube writes its indexes, plugins, and logs into those boxes, so the next container finds everything exactly as you left it.
Choosing Image Tags
The tag after the colon decides which edition and version you receive. The word community pulls the free build. A specific version number, such as one from the official tag list, freezes your setup at a known release. Production teams prefer fixed numbers, because a moving tag can change the version during a restart and surprise the team. Learners benefit from the simple tag, since it always offers the current build.
Connecting a Scanner to the Container
The scanner on your laptop reaches the container through the mapped port. Use http://localhost:9000 as the host address. A scanner that runs inside another container needs the compose service name instead, for example http://sonarqube:9000, and both containers must share a network. Compose creates that network automatically for services in the same file.
First Steps After Login
- Change the default password when SonarQube asks.
- Create a project manually from the Projects page.
- Generate a token under My Account.
- Run your first scan with the SonarScanner CLI.
Quick Recap
One command gives a trial server, and a compose file gives a durable setup with PostgreSQL and persistent volumes.
