How to Install Jenkins using Docker | Step by step guide | scmGalaxy

Step 1: Installing Docker
# apt-get install docker (Ubuntu)
# yum install docker  (RHEL/CENTOS)
Step 2:  First, pull the official jenkins image from Docker repository.
# docker pull jenkins

Step 3: Next, run a container using this image and map data directory from the container to the host; e.g in the example below /var/jenkins_home from the container is mapped to jenkins/ directory from the current path on the host. Jenkins 8080 port is also exposed to the host as 49001.

 

Mapping port 8080 on the host to the container (the web ui), port 50000 to port 50000 (for build agents). Run with `-p 50000:50000` so you can connect JNLP slaves. For port 50000. This is to handle connections from JNLP based build slaves. This will store the workspace in /var/jenkins_home. All Jenkins data lives in there including plugins and configuration.
> docker run -d -p 8080:8080 -p 50000:50000 jenkins
This will store the jenkins data in /your/home on the host. Ensure that /your/home is accessible by the jenkins user in container (jenkins user – uid 1000) or use -u some_other_user parameter with docker run.
> docker run -d -p 8080:8080 -p 50000:50000 -u root -v $PWD/jenkins:/var/jenkins_home jenkins
Other Example:
docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home -t jenkins -u root

 

This will store the jenkins data in /your/home on the host. Ensure that /your/home is accessible by the jenkins user in container (jenkins user – uid 1000) or use -u some_other_user parameter with docker run. This information is also found in the Dockerfile. So all you need to do is to ensure that the directory $PWD/jenkins is own by UID 1000:
> mkdir jenkins
> chown 1000 jenkins
> docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home -t jenkins

 

How to see the Jenkins log?

> docker exec name tail -f /var/log/jenkins/jenkins.log
Where name = –name

Step 3:  Access to j=Jenkins
As we have successfully run Jenkins Container, we can browse Jenkins Web Interface using our Web Browser by pointint to http://ip-address:49001 or http://localhost:49001 according to the configuration.
  • Biswa Mohanty

    UNABLE to access jenkins Home page:

    i freshly created an jenkins container from docker:

    [root@ip-172-31-86-217 ec2-user]# docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    de1b717bb052 jenkins “/bin/tini — /usr…” 3 minutes ago Exited (2) 3 minutes ago frosty_sinoussi
    b5d1a288417e jenkins/jenkins:lts “/sbin/tini — /us…” 6 minutes ago Up 6 minutes 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp epic_banach

    But I am unable to access the jenkins home URL : http://54.173.215.253:50000

© Tutorials
CyberChimps