How to run Jenkins on Docker container | How to create Jenkins Volumes on Docker

1. How to start Jenkins on Docker Container

 2. Start and Stop Jenkins Container

 3. How to set Jenkins home on Docker Volume and Host Machine

How to remove died container:

ubuntu@ip-172-31-39-216:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS               NAMES
efdab4e0a237        jenkins             "/bin/tini -- /usr/l…"   5 minutes ago       Exited (130) 9 seconds ago                       naughty_rubin

ubuntu@ip-172-31-39-216:~$ docker rm -f $(docker ps -a -q)
efdab4e0a237

 ubuntu@ip-172-31-39-216:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
ubuntu@ip-172-31-39-216:~$

1. How to start Jenkins on Docker Container:

ubuntu@ip-172-31-39-216:~$ docker run -p 8080:8080 -p 50000:50000 jenkins
Unable to find image 'jenkins:latest' locally
latest: Pulling from library/jenkins


ubuntu@ip-172-31-39-216:~$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                              NAMES
efdab4e0a237        jenkins             "/bin/tini -- /usr/l…"   51 seconds ago      Up 49 seconds       0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   naughty_rubin
 

 


 3. How to set Jenkins home on Docker Volume and Host Machine:

ubuntu@ip-172-31-39-216:~/raja_jenkin$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
jenkins             latest              cd14cecfdb3a        7 months ago        696MB
ubuntu@ip-172-31-39-216:~/raja_jenkin$ docker run --name  myjenkin -p 8080:8080 -p 50000:50000 -v /home/ubuntu/raja_jenkin:/var/jenkins_home jenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
Feb 20, 2019 4:24:14 AM Main deleteWinstoneTempContents
WARNING: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war
Feb 20, 2019 4:24:14 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Logging initialized @689ms
Feb 20, 2019 4:24:14 AM winstone.Logger logInternal
INFO: Beginning extraction from war file
Feb 20, 2019 4:24:16 AM org.eclipse.jetty.util.log.JavaUtilLog warn
WARNING: Empty contextPath
Feb 20, 2019 4:24:16 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: jetty-9.2.z-SNAPSHOT
Feb 20, 2019 4:24:17 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
Feb 20, 2019 4:24:18 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started w.@47404bea{/,file:/var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
Feb 20, 2019 4:24:18 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started ServerConnector@1c80e49b{HTTP/1.1}{0.0.0.0:8080}
Feb 20, 2019 4:24:18 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started @4048ms
Feb 20, 2019 4:24:18 AM winstone.Logger logInternal
INFO: Winstone Servlet Engine v2.0 running: controlPort=disabled
Feb 20, 2019 4:24:19 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started initialization
Feb 20, 2019 4:24:19 AM jenkins.InitReactorRunner$1 onAttained
INFO: Listed all plugins
Feb 20, 2019 4:24:21 AM jenkins.InitReactorRunner$1 onAttained
INFO: Prepared all plugins
Feb 20, 2019 4:24:21 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started all plugins
Feb 20, 2019 4:24:21 AM jenkins.InitReactorRunner$1 onAttained
INFO: Augmented all extensions
Feb 20, 2019 4:24:21 AM jenkins.InitReactorRunner$1 onAttained
INFO: Loaded all jobs
Feb 20, 2019 4:24:24 AM hudson.model.AsyncPeriodicWork$1 run
INFO: Started Download metadata
Feb 20, 2019 4:24:24 AM jenkins.util.groovy.GroovyHookScript execute
INFO: Executing /var/jenkins_home/init.groovy.d/tcp-slave-agent-port.groovy
Feb 20, 2019 4:24:25 AM jenkins.InitReactorRunner$1 onAttained
INFO: Completed initialization
Feb 20, 2019 4:24:26 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@784e1c44: display name [Root WebApplicationContext]; startup date [Wed Feb 20 04:24:26 UTC 2019]; root of context hierarchy
Feb 20, 2019 4:24:26 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@784e1c44]: org.springframework.beans.factory.support.DefaultListableBeanFactory@f1c44d7
Feb 20, 2019 4:24:26 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@f1c44d7: defining beans [authenticationManager]; root of factory hierarchy
Feb 20, 2019 4:24:26 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@72144a5: display name [Root WebApplicationContext]; startup date [Wed Feb 20 04:24:26 UTC 2019]; root of context hierarchy
Feb 20, 2019 4:24:26 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@72144a5]: org.springframework.beans.factory.support.DefaultListableBeanFactory@334fbbcc
Feb 20, 2019 4:24:26 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@334fbbcc: defining beans [filter,legacy]; root of factory hierarchy
Feb 20, 2019 4:24:27 AM jenkins.install.SetupWizard init
INFO:

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

588f07212a184235a96e25ebf94d87d6

This may also be found at: /var/jenkins_home/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

Feb 20, 2019 4:24:33 AM hudson.model.UpdateSite updateData
INFO: Obtained the latest update center data file for UpdateSource default
Feb 20, 2019 4:24:33 AM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
Feb 20, 2019 4:24:34 AM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tools.JDKInstaller
Feb 20, 2019 4:24:34 AM hudson.model.AsyncPeriodicWork$1 run
INFO: Finished Download metadata. 10,784 ms
--> setting agent port for jnlp
--> setting agent port for jnlp... done
Feb 20, 2019 4:24:35 AM hudson.model.UpdateSite updateData
INFO: Obtained the latest update center data file for UpdateSource default
Feb 20, 2019 4:24:35 AM hudson.WebAppMain$3 run
INFO: Jenkins is fully up and running



=> Then go browser and give IP and port:

http://18.218.46.245:8080/

* Then it will ask initial admin pass which is highlighted while install Jenkins session

Example:

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

588f07212a184235a96e25ebf94d87d6

This may also be found at: /var/jenkins_home/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

=> If you loss session password just goto "jenkin_home/secrets" folder and open "initialAdminPassword" file to get the password.

ubuntu@ip-172-31-39-216:~/raja_jenkin$ pwd
/home/ubuntu/raja_jenkin
ubuntu@ip-172-31-39-216:~/raja_jenkin$ cd secrets/

total 36
drwxr-xr-x 2 ubuntu ubuntu 4096 Feb 20 04:24 whitelisted-callables.d
drwxr-xr-x 2 ubuntu ubuntu 4096 Feb 20 04:24 filepath-filters.d
-rw-r--r-- 1 ubuntu ubuntu  256 Feb 20 04:24 master.key
-rw-r--r-- 1 ubuntu ubuntu   32 Feb 20 04:24 jenkins.model.Jenkins.crumbSalt
-rw-r--r-- 1 ubuntu ubuntu  272 Feb 20 04:24 org.jenkinsci.main.modules.instance_identity.InstanceIdentity.KEY
-rw-r--r-- 1 ubuntu ubuntu   48 Feb 20 04:24 jenkins.security.ApiTokenProperty.seed
-rw-r--r-- 1 ubuntu ubuntu  272 Feb 20 04:24 hudson.util.Secret
-rw-r----- 1 ubuntu ubuntu   33 Feb 20 04:24 initialAdminPassword
-rw-r--r-- 1 ubuntu ubuntu    5 Feb 20 04:24 slave-to-master-security-kill-switch
ubuntu@ip-172-31-39-216:~/raja_jenkin/secrets$ cat initialAdminPassword
588f07212a184235a96e25ebf94d87d6
ubuntu@ip-172-31-39-216:~/raja_jenkin/secrets$ pwd
/home/ubuntu/raja_jenkin/secrets

======================================================================
=> login to  jenkins "http://18.218.46.245:8080/" and create item which basic plugins and save it.

Docker volume concept:
 
=>Then here I'm going to stop and remove the container which we have started few minutes back. And i will start the new container with same Jenkins home which is available in Ur local(ec2 machine).

ubuntu@ip-172-31-39-216:~/raja_jenkin/secrets$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                              NAMES
e974d6a14fa2        jenkins             "/bin/tini -- /usr/l…"   13 minutes ago      Up 13 minutes       0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   myjenkin
ubuntu@ip-172-31-39-216:~/raja_jenkin/secrets$ docker stop myjenkin
myjenkin
ubuntu@ip-172-31-39-216:~/raja_jenkin/secrets$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
ubuntu@ip-172-31-39-216:~/raja_jenkin/secrets$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES
e974d6a14fa2        jenkins             "/bin/tini -- /usr/l…"   14 minutes ago      Exited (143) 21 seconds ago                       myjenkin
ubuntu@ip-172-31-39-216:~/raja_jenkin/secrets$ docker rm myjenkin
myjenkin
ubuntu@ip-172-31-39-216:~/raja_jenkin/secrets$


NEED to START the JENKIN:

ubuntu@ip-172-31-39-216:~/raja_jenkin$ docker run --name  myjenkin_vol -p 8080:8080 -p 50000:50000 -v /home/ubuntu/raja_jenkin:/var/jenkins_home jenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
Feb 20, 2019 4:52:37 AM Main deleteWinstoneTempContents
WARNING: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war
Feb 20, 2019 4:52:37 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Logging initialized @616ms
Feb 20, 2019 4:52:37 AM winstone.Logger logInternal
INFO: Beginning extraction from war file
Feb 20, 2019 4:52:37 AM org.eclipse.jetty.util.log.JavaUtilLog warn
WARNING: Empty contextPath
Feb 20, 2019 4:52:37 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: jetty-9.2.z-SNAPSHOT
Feb 20, 2019 4:52:38 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
Feb 20, 2019 4:52:39 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started w.@25ce9dc4{/,file:/var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
Feb 20, 2019 4:52:39 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started ServerConnector@cb0755b{HTTP/1.1}{0.0.0.0:8080}
Feb 20, 2019 4:52:39 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started @2656ms
Feb 20, 2019 4:52:39 AM winstone.Logger logInternal
INFO: Winstone Servlet Engine v2.0 running: controlPort=disabled
Feb 20, 2019 4:52:40 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started initialization
Feb 20, 2019 4:52:40 AM jenkins.InitReactorRunner$1 onAttained
INFO: Listed all plugins
Feb 20, 2019 4:52:42 AM jenkins.InitReactorRunner$1 onAttained
INFO: Prepared all plugins
Feb 20, 2019 4:52:42 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started all plugins
Feb 20, 2019 4:52:42 AM jenkins.InitReactorRunner$1 onAttained
INFO: Augmented all extensions
Feb 20, 2019 4:52:43 AM jenkins.InitReactorRunner$1 onAttained
INFO: Loaded all jobs
Feb 20, 2019 4:52:43 AM hudson.model.AsyncPeriodicWork$1 run
INFO: Started Download metadata
Feb 20, 2019 4:52:43 AM hudson.model.AsyncPeriodicWork$1 run
INFO: Finished Download metadata. 12 ms
Feb 20, 2019 4:52:43 AM jenkins.util.groovy.GroovyHookScript execute
INFO: Executing /var/jenkins_home/init.groovy.d/tcp-slave-agent-port.groovy
Feb 20, 2019 4:52:44 AM jenkins.InitReactorRunner$1 onAttained
INFO: Completed initialization
Feb 20, 2019 4:52:44 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@3d43bdd8: display name [Root WebApplicationContext]; startup date [Wed Feb 20 04:52:44 UTC 2019]; root of context hierarchy
Feb 20, 2019 4:52:44 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@3d43bdd8]: org.springframework.beans.factory.support.DefaultListableBeanFactory@9174961
Feb 20, 2019 4:52:44 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@9174961: defining beans [authenticationManager]; root of factory hierarchy
Feb 20, 2019 4:52:44 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@7aff1539: display name [Root WebApplicationContext]; startup date [Wed Feb 20 04:52:44 UTC 2019]; root of context hierarchy
Feb 20, 2019 4:52:44 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@7aff1539]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1195e493
Feb 20, 2019 4:52:44 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1195e493: defining beans [filter,legacy]; root of factory hierarchy
Feb 20, 2019 4:52:44 AM hudson.WebAppMain$3 run
INFO: Jenkins is fully up and running
--> setting agent port for jnlp
--> setting agent port for jnlp... done




NOTE: Here we can login the jenkin as admin user whcih you have reset the password earlier.

Comments

Popular posts from this blog

POWERSHELL

Building game of life container