22.9 C
Texas
angeloma
Senior Writer and partner

How to deploy Jenkins using docker-compose?

We already know the potential of Docker and how easy it is to display images thanks to Docker-compose. In this post, you will learn how to deploy Jenkins using Docker-compose. This is in order to avoid manual installation of the application. Moreover, with this method, you do not have to worry about the operating system but just have Docker installed.

Install Docker and Docker-compose

The first thing to do is to install Docker and Docker compose in our system. In the case of Debian 10, there is a tutorial of ours that you can use as a guide.

For the rest of the distributions, it is a good idea to read Docker’s official documentation. Anyway, it is not hard to do.

Deploy Jenkins using Docker-compose

As we explained in the post to deploy LAMP using Docker-compose, the definitions of images and their options, we do them in a file with the extension YML. To do this, it is recommended to first make a folder and within it create the file.

- Advertisement -

So, open a terminal session and type the following:

:~$ mkdir jenkins && cd jenkins

Once we have entered the folder using your favorite text editor proceed to create the docker-compose.yml file.

:~$ nano docker-compose.yml

Once inside, we will begin to define the content.

version: '2'
services:
  jenkins:
  image: 'bitnami/jenkins:2'

First the basic file definitions. The version to use will be the 2. And we will deploy only a service that will be called jenkins. For it, we will use the image Jenkins of bitnami. It is very well documented and quite reliable.

Then, we continue with the definition of the options.

ports:
      - '80:8080'
      - '443:8443'
      - '50000:50000'
    volumes:
      - 'jenkins_data:/bitnami'
volumes:
  jenkins_data:
  driver: local

In this section, you define the ports that the image will use. Remember that Jenkins uses the 8080 but we will access the 8080 port of the image through the 80. So, the 443 is for secure connections with Jenkins.

Equally, with LAMP, it is advisable to mount a volume for the Jenkins data. And at the end of the file, we refer to the options of that volume.

So, the file will be completed as follows:

version: '2'
services:
  jenkins:
    image: 'bitnami/jenkins:2'
    ports:
      - '80:8080'
      - '443:8443'
      - '50000:50000'
    volumes:
      - 'jenkins_data:/bitnami'
volumes:
  jenkins_data:
  driver: local

1.- Docker-compose file for Jenkins
1.- Docker-compose file for Jenkins

We can now raise the image, but I want to show you a few more options.

Some useful options to deploy Jenkins

This Jenkins image is customizable thanks to environment variables that can be modified. Some of them are these:

  • JENKINS_USERNAME: Jenkins admin username.
  • JENKINS_PASSWORD: Jenkins admin password.
  • JENKINS_HOME: Jenkins home directory.
  • DISABLE_JENKINS_INITIALIZATION: Allows to disable the initial Bitnami configuration for Jenkins.
  • JAVA_OPTS: Customize JVM parameters.

To use and modify them, just add them to the file in the environment section. For example:

jenkins:
  ...
  environment:
    - JENKINS_PASSWORD=your-password
  ...

Note: by default the user is user and the password is bitnami. Then, you can modify it from Jenkins once it has been deployed.

Running and testing Jenkins

Once you have finished defining the docker-compose file. Now we can execute it with the following command:

:~$ sudo docker-compose up -d

2.- Deploy Jenkins using docker-compose
2.- Deploy Jenkins using docker-compose

Next, open your web browser and go to your server using the port 80.

3.- Jenkins is almost ready to work
3.- Jenkins is almost ready to work

Then, login into the application using the default credentials or yours.

4.- Jenkins log in screen
4.- Jenkins log in screen

After that, you will see the dashboard.

5.- Everything is OK
5.- Everything is OK

And that is it.

Conclusion

Jenkins is a very popular application and it is possible to install it on our server using docker. This way we save a lot of time on some operating-system configurations. However, for total control of it, it is advisable to do it manually.

You can read How to install Jenkins on Debian 10?

Please share this post and join our Telegram channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article