Team of Programmer working to find solution to problem and coding technologies in a software developing company office.
Image: snowing12/Adobe Stock

SonarQube is a continuous code inspection tool that is used for the automatic inspection of code quality. The tool runs these automated reviews to detect bugs and code smells (deeper problems) in 29 programming languages. SonarQube presents itself with a user-friendly web-based GUI and can be deployed as a docker container.

SEE: Hiring kit: Back-end Developer (TechRepublic Premium)

And that, my friends, is exactly what I’m going to do. With the help of Ubuntu Server 22.04 and Docker Compose, we’re going to deploy SonarQube.

One thing to keep in mind is that this deployment uses an embedded database, which does not scale. If you know you’re going to need to use SonarCube for larger projects, you’ll want to go through the steps for the full installation, which I covered in “How to install the SonarQube code quality analyzer on Ubuntu Server 20.04.” For smaller projects, deploying with Docker is a great option to get SonarCube up and running quickly.

What you’ll need to deploy SonarQube

The only things you’ll need for this are a running instance of Ubuntu Server 22.04 — this can also be done on any Ubuntu-based distribution — and a user with sudo privileges.

How to install Docker Compose

One of the reasons why I prefer deploying SonarQube with Ubuntu Server is how easy Docker is to install. Log in to your Ubuntu instance, open a terminal window, and issue the command:

sudo apt-get install docker-compose -y

The above installation will also install the docker command, which you’ll use to deploy SonarQube. Once the installation completes, you’ll need to add your user to the docker group with:

sudo usermod -aG docker $USER

Log out and log back in again so the changes take effect.

How to pull the latest SonarQube image

The first step is to pull the official SonarQube image, which is done with the command:

docker pull sonarqube

How to create the necessary volumes

Next, we’ll create the necessary volumes for SonarQube with the following commands:

docker volume create sonarqube-conf
docker volume create sonarqube-data
docker volume create sonarqube-logs
docker volume create sonarqube-extensions

How to deploy SonarQube

With everything ready, deploy the container with the command:

docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 -v sonarqube-conf:/opt/sonarqube/conf -v sonarqube-data:/opt/sonarqube/data -v sonarqube-logs:/opt/sonarqube/logs -v sonarqube-extensions:/opt/sonarqube/extensions sonarqube

Give the container a couple of minutes to deploy.

How to access SonarQube

Before you can actually log into SonarQube, you must first set up the database. This is actually very simple. Open a web browser and point it to http://SERVER:9000/setup, where SERVER is the IP address of the hosting server. You should then be presented with a link labeled HOME. Click that and you should then see the SonarQube log-in window (Figure A).

Figure A

The SonarCube login window.

The default credentials are admin/admin. Upon successful authentication, you’ll be presented with a password update window (Figure B).

Figure B

Updating the password for the admin user in SonarQube.

Once you’ve updated the password, you’ll be presented with the SonarCube main window (Figure C), where you can begin to create your first project.

Figure C

The SonarCube main window.

And that’s all there is to deploying SonarCube with Docker. Although this instance might not scale to meet your needs, it’s a great way of checking for issues on small-to-mid-sized projects.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.