Running SonarQube with Docker
Code quality analysis in one command
Need to analyze your code quality? SonarQube is the tool for that. It catches bugs, code smells, and security issues before they make it to production.
Running it with Docker is the easiest way. No complicated setup, no dependency hell. Just one command.
What You Need
- Docker installed
- At least 2GB of RAM available
- Port 9000 free
The Command
Here's all you need:
docker run -dit --name sonarqube -p 9000:9000 sonarqube:lts-community
Let me break down what this does:
-dit- Runs in detached mode with an interactive terminal--name sonarqube- Names the container "sonarqube"-p 9000:9000- Maps port 9000 to your hostsonarqube:lts-community- Uses the LTS Community Edition
Docker will download the image (about 500MB) and start the container. Takes a couple of minutes depending on your internet speed.
Wait for It to Start
SonarQube needs a minute or two to initialize. Check the logs:
docker logs -f sonarqube
Wait until you see "SonarQube is operational". Press Ctrl+C to exit the logs.
First time startup: SonarQube needs time to set up its embedded database. Be patient. It's worth the wait.
Access SonarQube
Open your browser and go to:
http://localhost:9000
The default credentials are:
- Username:
admin - Password:
admin
It'll ask you to change the password on first login. Do that.
Security reminder: Change that default password immediately. Seriously. Don't skip this.
Manage the Container
Here are some useful commands:
# Stop SonarQube
docker stop sonarqube
# Start it again
docker start sonarqube
# Restart
docker restart sonarqube
# Remove container (your data will be lost!)
docker rm -f sonarqube
Persist Your Data
The basic command works fine, but you'll lose all your data if you remove the container. For production or long-term use, add volumes:
docker run -dit --name sonarqube \
-p 9000:9000 \
-v sonarqube_data:/opt/sonarqube/data \
-v sonarqube_logs:/opt/sonarqube/logs \
-v sonarqube_extensions:/opt/sonarqube/extensions \
sonarqube:lts-community
Now your data persists even if you recreate the container.
System Requirements
If SonarQube doesn't start or runs slowly, check these:
- At least 2GB RAM allocated to Docker
- Enough disk space (at least 5GB free)
- vm.max_map_count set properly (Linux)
On Linux, if you get errors about max_map_count, run:
sudo sysctl -w vm.max_map_count=524288
Next Steps
Once you're logged in, create a new project. SonarQube will give you a token and instructions for scanning your code. You can integrate it with Jenkins, GitHub Actions, GitLab CI, or run scans manually.
Pro tip: Install SonarLint in your IDE (VS Code, IntelliJ, etc.) to catch issues while you code, before you even push to SonarQube.
That's It
SonarQube is running and ready to analyze your code. One command, no hassle. Docker makes it that easy.
Happy analyzing! 🔍
Comments
Post a Comment