DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Smart Deployment Strategies for Modern Applications
  • Solving the Mystery: Why Java RSS Grows in Docker on M1 Macs
  • How We Diagnosed a Hidden Scheduler Failure in a Docker Swarm Cluster Serving 2 Million Users
  • Java Backend Development in the Era of Kubernetes and Docker

Trending

  • Stop Debugging Glue Jobs Manually: Building an Agentic Observability Layer for Data Pipelines
  • Observability for Agents and Workflows: Tracing Prompts, Tool Calls, and Business Outcomes End-to-End
  • When One MVP Is Really Four Systems: A Better Way to Plan Multi-Role Apps
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 1
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Running SonarQube Inside a Docker Container

Running SonarQube Inside a Docker Container

We're gonna see how we can run a sonar-server inside a docker container and analyze your project. We will explore local URL to public URL.

By 
Amit Mishra user avatar
Amit Mishra
·
Dec. 17, 20 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
14.8K Views

Join the DZone community and get the full member experience.

Join For Free

Prerequisite

To follow this article, one will need to make sure that they have docker installed in their machine. I assume you know using docker containers. I will be analyzing a maven project, so please make sure that you've one maven project with some code that you can analyze.

Introduction

Sonarqube is a prevalent tool for analyzing bugs, Vulnerabilities, Security hotspots, and some other programming standards. You can use this tool to analyze your project's source code to keep your code standing with programming standards. Using SonarQube is very easy. You can download the sonar server from the official site, but we will be running SonarQube inside a docker container to analyze our source code in this article. 

Getting Started 

The first thing is to pull a docker image from using SonarQube's community edition docker image. Pull the docker image in your local machine by running this command:

Shell
 




x


 
1
docker pull SonarQube:8.2-community



Once you have this image in your local machine, run the following command to run the sonar-server inside a docker container.

Shell
 




xxxxxxxxxx
1


 
1
docker container run -d -p 9000:9000 --name sonarserver SonarQube:8.2-community



This will start your sonar server on port 9000. After a few minutes, open the URL localhost:9000. There you will be asked to log in, and the default username and password is admin.

Once we're logged in to create a new project and analyze the source code, click on the + icon on the top right corner of the window and Enter your project key and display name, now you will need to generate a token for your project. 

Select your project; I am choosing java and build type as Maven.  Once you select the type it will give you some code snippet like so

Shell
 




x


 
1
mvn sonar:sonar \
2
  -Dsonar.projectKey=Your Project Key \
3
  -Dsonar.host.url=http://localhost:9000 \
4
  -Dsonar.login=5d6b3ef3c855ac7e754f3ac6acccede63893c083



At this point, you need to go to your projects folder and open a terminal there and run the following maven command. The command will analyze the code and push the information on the sonar server, and there you can view the analysis of your code. 

Proxying Your Local HTTP Port to a Public URL

In this section, I will tell you a better way to proxy your local HTTP ports to a public URL so that you can map your incoming traffic of a public URL to your local server. There is an application called ngrok. You will need to create an account there, download the ngrok application, and then run the following command. 

Shell
 




xxxxxxxxxx
1


 
1
./ngrok http your_local_port
2

          
3
#It will give you some randomly generated url.
4
#The public url will map all incoming traffic with your local server



Ngrok was something that I just wanted to share, and I personally liked; it has nothing to do with SonarQube. With that being said, I would like to thank you guys for taking the time to read out my post.

Docker (software)

Opinions expressed by DZone contributors are their own.

Related

  • Smart Deployment Strategies for Modern Applications
  • Solving the Mystery: Why Java RSS Grows in Docker on M1 Macs
  • How We Diagnosed a Hidden Scheduler Failure in a Docker Swarm Cluster Serving 2 Million Users
  • Java Backend Development in the Era of Kubernetes and Docker

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook