How to deploy SonarQube with Docker

Jack Wallen shows you how to deploy the SonarQube continuous code inspection tool with Docker on Ubuntu Server 22.04.

Team of programmers working to find solutions to problems and coding technologies in a software development company office.
Image: snowing12/Adobe Stock

SonarQube is a continuous code inspection tool used to automatically verify code quality. The tool runs these automated checks to detect bugs and code smells (deeper problems) in 29 different programming languages. SonarQube comes with an easy-to-use web-based GUI and can be deployed as a Docker container.

SEE: Hire Kit: Backend Developer (TechRepublic Premium)

And that, my friends, is exactly what I will do. Using Ubuntu Server 22.04 and Docker Compose, we will deploy SonarQube.

Note that this deployment uses an embedded database that is not scalable. If you know you need to use SonarCube for larger projects, you should go through the full installation steps 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 need to deploy SonarQube

The only things you 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 I prefer to deploy SonarQube with Ubuntu Server is the ease of installing Docker. Login to your Ubuntu instance, open a terminal window and enter the command:

sudo apt-get install docker-compose -y

The installation above also installs the Docker command that you will use to deploy SonarQube. Once the installation is complete you need to add your user to the docker group with:

sudo usermod -aG docker $USER

Log out and back in for the changes to take effect.

How to pull the latest SonarQube image

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

docker pull sonarqube

How to create the required volumes

Next we create the required 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

When everything is 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 few minutes to deploy.

How to access SonarQube

Before you can actually log into SonarQube, you must first set up the database. This is actually quite 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 see a link labeled HOME. Click on that and you should then see the SonarQube login window (Figure A).

Figure A

The SonarCube login window.

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

Figure B

Updating the password for the admin user in SonarQube.

Once you have updated the password, you will be presented with the SonarCube main window (Figure C) where you can start creating your first project.

Figure C

The SonarCube main window.

And that’s all to deploy SonarCube with Docker. While this instance may not meet your needs, it’s a great way to troubleshoot small to medium-sized projects.

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

Leave a Reply

Your email address will not be published. Required fields are marked *