Jenkins via Docker Compose

Installation Link

Installing Jenkins via Docker

  1. Use docker run:

docker run --name my-jenkins-1 -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
  1. After running the command above, Docker starts to create a new container. Once the Jenkins container is running, take note of the initial admin password displayed on the terminal. The admin password is needed during the Jenkins initial setup.

  2. After the Jenkins container entered the running state, you can now access the Jenkins admin page. If you remember from the command you used to create the container, the port number is 8080. So to access the Jenkins instance, navigate to HTTP://localhost:8080

Note: You can access the Jenkis instance by using IP as well

HTTP://ip-of-server:8080

3. On the Customize Jenkins page, you’ll have the option to Install suggested plugins. These suggested plugin are the plugins that the Jenkins community typically install. If you have a pre-selected set of plugins to install, choose the Select plugins to install option.

For simplicity, the Install suggested plugins is the selected option for this example.

  1. The plugins will be installed, and you can only wait until the installation is finished. As you can see below, there are fourteen (14) suggested plugins being installed. The number of recommended plugins may increase or decrease over time. By the time you installed your Jenkins instance, the suggested plugins may already be different.

  2. Immediately after the plugins’ installation finished, you will see the Create First Admin User page. This page is where you will create the first Jenkins administrator account. Fill in all the boxes as required and click on Save and Continue. Make sure to remember the administrator credential you have just created.

  3. On the Instance Configuration page is where you can change the Jenkins admin page URL. The URL value would typically be the actual URL that will be accessed by the Jenkins users.

For this example, leave the default value of http://localhost:8080 and click on Save and Finish.

4. On the final setup page, you will see the confirmation that the Jenkins setup is complete. Click on Start using Jenkins.

When you see the Welcome to Jenkins page, as shown below, then you’ve completed the Jenkins installation. At this point, you can start configuring Jenkins and creating new items or projects.

Finding the Jenkins Data on the Docker Host

Where’s the Jenkins data folder now?

Based on the command you used to create the my-jenkins-2 container, the mounted volume is jenkins_home. To know where in the filesystem is the jenkins_home location can be found, use the docker volume command.

docker volume inspect jenkins_home

Now that you know where to find the Jenkins data, you can confirm by exploring the mount point location.

In this example, the jenkins_home volume mount point is in /var/lib/docker/volumes/jenkins_home/_data

Now that the Jenkins data persists outside of the container, you can backup the directory for safekeeping.

Also, even if the Jenkins container is deleted, the data will remain on the Docker host

Creating the Docker Compose Files

version: '3.3'
services:
  jenkins:
    image: "jenkins/jenkins:lts"
    user: root
    expose:
      - 8080
    ports:
      - 50000:50000
    container_name: it-jenkins
    volumes:
      - ~/jenkins:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/local/bin/docker:/usr/local/bin/docker
    networks:
      - jenkins_nw
    restart: unless-stopped
  nginx:
    image: "nginx:latest"
    links:
      - "jenkins"
      - "jenkins:jenkinssvc"
    ports:
      - "80:80"
      - "443:443"
    container_name: it-nginx
    volumes:
      - ~/certs:/etc/ssl
      - ~/nginx/conf.d:/etc/nginx/conf.d
      - /var/run/docker.sock:/tmp/docker.sock:ro
    networks:
      - jenkins_nw
    depends_on:
      - jenkins
    restart: unless-stopped
 
networks:
  jenkins_nw:
    driver: bridge

To start the jenkins-01 container, use the command below

Note: The command below assumes that the docker-compose.yml file is in the same directory where you run the command.

# Start the jenkins-01 container
docker-compose up -d

# Get the initial admin password
docker exec jenkins-01 cat /var/jenkins_home/secrets/initialAdminPassword

# Confirm the my-jenkins-3 container is running
docker ps

Note: If there is a firewall unblock port

ufw allow 8083

Last updated