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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Chaos Engineering and Kafka In Action: Topic Level Idempotence and Retry Check
  • Deploying Small Language Models on Sovereign Cloud
  • How to Keep AI Agents From Going Rogue Using Docker Sandbox
  • When One Docker Swarm Replica Became Unreachable Over an Overlay Network: A Production Case With Traefik

Trending

  • Architecture Review Boards for Generative AI: A Framework for Governance, Risk Management, and Responsible Adoption
  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • Build a Voice Assistant With Gemini Live API
  • Kafka Consumers on EKS: Designing for a Platform That Restarts Your Consumer Group

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Dec. 17, 20 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
15.0K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • Chaos Engineering and Kafka In Action: Topic Level Idempotence and Retry Check
  • Deploying Small Language Models on Sovereign Cloud
  • How to Keep AI Agents From Going Rogue Using Docker Sandbox
  • When One Docker Swarm Replica Became Unreachable Over an Overlay Network: A Production Case With Traefik

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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