Jenkins & Nexus & SonarQube: Build the DevOps environment using Docker-Compose

Jenkins & Nexus & SonarQube: Build the DevOps environment using Docker-Compose

This is another my post in which I present in a simple way how to set up the environment using the benefits of Docker-Compose.

This time we will focus on an example where we will configure an environment consisting of:

  • Jenkins
  • SonarQube + PostgreSQL
  • Nexus

docker-compose.yml script

version: "3"
services:
  jenkins:
    image: jenkinsci/blueocean
    container_name: jenkins
    environment:
      - DOCKER_HOST=tcp://localhost:2375
      - JENKINS_UC=http://updates.jenkins.io
      - JENKINS_UC_EXPERIMENTAL=http://updates.jenkins.io/experimental
      - JENKINS_INCREMENTALS_REPO_MIRROR=http://repo.jenkins-ci.org/incrementals
    user: root
    ports:
      - "8080:8080"
      - "8443:8443"
      - "50000:50000"  
    expose:
      - "8080"
    volumes:
      - jenkins-data:/var/jenkins_home
      - jenkins-home:/home


  nexus:
    image: sonatype/nexus3
    container_name: nexus
    volumes:
      - "nexus-data:/nexus-data"
    ports:
      - "8081:8081"
    expose:
      - "8081"

  sonarqube:
    image: sonarqube
    container_name: sonarqube
    ports:
      - "9000:9000"
    environment:
      - sonar.jdbc.url=jdbc:postgresql://db:5432/sonar
    volumes:
      - sonarqube_conf:/opt/sonarqube/conf
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions

  db:
    image: postgres
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=sonar
    volumes:
      - postgresql:/var/lib/postgresql
      # This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52
      - postgresql_data:/var/lib/postgresql/data

volumes:
  nexus-data: {}
  jenkins-data: {}
  jenkins-home: {}
  sonarqube_conf: {}
  sonarqube_data: {}
  sonarqube_extensions: {}
  postgresql: {}
  postgresql_data: {}

Check container status

Before we start the further part of the configuration, check that all containers are in “UP” status.

docker-compose ps
          Name                        Command               State                                    Ports                                  
--------------------------------------------------------------------------------------------------------------------------------------------
jenkins                    /sbin/tini -- /usr/local/b ...   Up      0.0.0.0:50000->50000/tcp, 0.0.0.0:8080->8080/tcp, 0.0.0.0:8443->8443/tcp
jenkins_nexus_sonar_db_1   docker-entrypoint.sh postgres    Up      5432/tcp                                                                
nexus                      sh -c ${SONATYPE_DIR}/star ...   Up      0.0.0.0:8081->8081/tcp                                                  
sonarqube                  ./bin/run.sh                     Up      0.0.0.0:9000->9000/tcp 

Jenkins – first run

The Jenkins user interface is available at: http://localhost:8080

At the first start we will be asked to enter the administrator password, which is saved in the file: /var/jenkins_home/secrets/initialAdminPassword, which is located on the container file system with Jenkins. To open the contents of this file we must “enter” this container using SSH. To do this, run the following command from the terminal:

# docker exec -it <docker_container_name>  /bin/bash
docker exec -it jenkins /bin/bash

Once inside the container, run the command below. The string is our administrator password.

cat /var/jenkins_home/secrets/initialAdminPassword
1367d1e351194e839abb21682498e63d

Plugins installation

Następnie zainstaluj sugerowane wtyczki. Jest to zbiór podstawowych rozszerzeń, które można traktować jako pakiet startowy.

Creating an administrator account

The next step is to create an administrator account.

After creating the admin account, we can fully use Jenkins.

Nexus – first run

The Nexus user interface is available at: http://localhost:8081

When you try to log in for the first time, we will receive information that the admin user password has been generated and is located under the path: /nexus-data/admin.password. Let’s check the password!

Using the command below we will enter to the Nexus container.

docker exec -it nexus /bin/bash

cat /nexus-data/admin.password
05feffa3-f8e3-49ed-b765-002d6b90d2a5

We paste the above password into the login form. Then we will be asked to set your password, which I encourage.

SonarQube – first run

The SonarQube user interface is available at: http://localhost:9000

Click the “Log-in” button in the upper right corner. The default administrator user is admin and the password is also admin.

Summary

As you can see, creating an environment with docker-compose is really easy. In a few minutes we can create and start using tools.

To sum up, below is a list of URLs to:

If you enjoyed this post please add the comment below or share this post on your Facebook, Twitter, LinkedIn or another social media webpage.
Thanks in advanced!

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu