Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SudarshanTevari/9b34d654d3b8fad38884e4109ab1a8f3 to your computer and use it in GitHub Desktop.
Save SudarshanTevari/9b34d654d3b8fad38884e4109ab1a8f3 to your computer and use it in GitHub Desktop.
Setup SonarQube on docker container

How to setup SonarQube with PostgreSQL DB on Docker Container?

  • Let's start creating a docker network for both SonarQube and PostgreSQL database, as they both need to be on the same network to communicate with each other.
  • If you are restarting the server make sure the docker service is enabled so that it will automatically start SonarQube and PostgreSQL docker containers.

You can enable docker by passing command:

sudo systemctl enable docker

Start with cleaning process:

If there is any docker container with either SonarQube or Postgres, let's delete it and create a new one.

#SonarQube
docker stop sonarqube
docker rm sonarqube
  
#PostgreSQL
docker stop postgres
docker rm postgres

If there is any docker network with the same name, let's delete it and create a new one.

docker network rm sonarqube_network

Container creation process:

Creating new docker network...

docker network create sonarqube_network

Creating new PostgreSQL docker container...

docker run --name postgres --restart=always -e POSTGRES_USER=root -e POSTGRES_PASSWORD=Mypass12345 -p 5432:5432 --network sonarqube_network -d postgres

Creating new SonarQube docker container...

docker run -d --name sonarqube --restart=always -p 9000:9000 -e sonar.jdbc.url=jdbc:postgresql://postgres/postgres -e sonar.jdbc.username=root -e sonar.jdbc.password=Mypass12345 --network sonarqube_network sonarqube

If you already have container running and you want to automatically start the container after every server restart, then use the following command;

docker update --restart=always [container id or container name]

Verification:

Now you should be able to use SonarQube in Jenkins pipeline for Continuous Inspection, by configuring SonarQube into Jenkins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment