An Enthusiastic Programmer

Install Jenkins Using Docker

|

To get the start, you need to install Jenkins. There are plenty of ways you can achieve this goal. You can build from source code, run war file in Java, or run from a Docker image. etc.

Generally, Jenkins provides two major releases, weekly and lts. Weekly, as the name says, new releases are produced weekly to deliver bug fixes and features to users and plugin developers. lts, every 12 weeks from the stream of regular releases as the stable release for that time period.

Here, I am gonna illustrate that install Jenkins using Docker. If you run Jenkins using Docker, you have to fit these prerequisites:

  1. A256 MB of RAM
  2. 1 GB of drive space (although 10 GB is a recommended minimum if running Jenkins as a Docker container)

The next step, create a docker-compose.yaml file. And place your instructions into it.

docker-compose.yaml

version: '3.9'
services:
  jenkins:
    image: jenkins/jenkins:lts
    ports:
      - 8080:8080
      - 50000:50000
    volumes:
      - ./jenkins_home:/var/jenkins_home/
    restart: always
    privileged: true
    user: root

The above docker-compose file grants its admin permission by privileged: true and user: root. And mounting Jenkins folder to /var/jenkins_home inside the container’s instance. Take a loot at Official Jenkins Docker image for more details.

Navigate to the same folder where you place the docker-compose.yaml file. Then expose your application up.

$ docker-compose up -d

You can also use docker command directly.

docker run \
-v $(pwd)/jenkins_home:/var/jenkins_home  \
-d  \
-p 8080:8080  \
-p 50000:50000  \
-u root \
jenkins/jenkins:lts 
NOTE: The above command probably will run your Jenkins web application on a private network. If you can't access your Jenkins remotely(such as: running on a VPS), you can add --net host to use the host network instead of using the default bridge. You can run docker network list to list all of available network objects on your machine.

Docker compose with host network mode:

version: '3.9'
services:
  jenkins:
    image: jenkins/jenkins:lts
    volumes:
      - ./jenkins_home:/var/jenkins_home/
    restart: always
    privileged: true
    user: root
    network_mode: "host"

Or using docker command directly.

docker run  \
-v $(pwd)/jenkins_home:/var/jenkins_home  \
-d  \
-u root  \
--net host   \
jenkins/jenkins:lts

The host network mode instructs docker daemon to use your host’s network. So you don’t need to specify the ports mapping anymore(beacuase it directly runs on your host’s network). Once your Jenkins is running up, access your Jenkins on the browser at server_ip:8080, the default port is 8080.

You will see someting like this for setup wizard.

Altsetup wizard

check your initial admin password

$ docker exec <containerid> cat /var/jenkins_home/secrets/initialAdminPassword

Altinstall plugins

AltAdd first admin user

AltJenkins Dashboard

Now, a Jenkins instance is fully set up. And in the next articles, I will discuss how to use the Jenkins dashboard.

Comments