Docker拉取镜像
[root@iZuf6h59snssqyqa3ka87eZ ~]# docker search jenkins
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/jenkins Official Jenkins Docker image 3311 [OK]
docker.io docker.io/jenkins/jenkins The leading open source automation server 412
docker.io docker.io/jenkinsci/jenkins Jenkins Continuous Integration and Deliver... 309
docker.io docker.io/jenkinsci/blueocean https://jenkins.io/projects/blueocean 91
docker.io docker.io/jenkinsci/jnlp-slave A Jenkins slave using JNLP to establish co... 72 [OK]
docker.io docker.io/jenkinsci/slave Base Jenkins slave docker image 29 [OK]
docker.io docker.io/cloudbees/jenkins-enterprise CloudBees Jenkins Enterprise (Rolling rele... 26 [OK]
docker.io docker.io/aespinosa/jenkins Sets up a container with jenkins installed... 22 [OK]
docker.io docker.io/cloudbees/jenkins-operations-center CloudBees Jenkins Operation Center (Rollin... 10 [OK]
docker.io docker.io/killercentury/jenkins-slave-dind Generic Jenkins Slave with Docker Engine a... 9 [OK]
docker.io docker.io/openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use... 9
docker.io docker.io/fabric8/jenkins-docker Fabric8 Jenkins Docker Image 8 [OK]
docker.io docker.io/jenkins/jnlp-slave a Jenkins agent (FKA "slave") using JNLP t... 7 [OK]
docker.io docker.io/logimethods/jenkins To allow Docker based builds through a Doc... 5 [OK]
docker.io docker.io/vfarcic/jenkins-swarm-agent Jenkins agent based on the Swarm plugin 5 [OK]
docker.io docker.io/publicisworldwide/jenkins-slave Jenkins Slave based on Oracle Linux 4 [OK]
docker.io docker.io/camper83/jenkins-slave-with-docker-compose jenkins slave with docker compose 3 [OK]
docker.io docker.io/openshift/jenkins-1-centos7 DEPRECATED: A Centos7 based Jenkins v1.x i... 3
docker.io docker.io/yasn77/docker-jenkins-slave Docker Jenkins slave image using swarm plu... 3 [OK]
docker.io docker.io/enieuw/jenkins Jenkins 1 [OK]
docker.io docker.io/ansibleplaybookbundle/jenkins-apb An APB which deploys Jenkins CI 0 [OK]
docker.io docker.io/h1kkan/jenkins-docker ?? Extended Jenkins docker image, bundle... 0
docker.io docker.io/hivesolutions/jenkins_slave Slave container to be used in jenkins. 0 [OK]
docker.io docker.io/jameseckersall/jenkins docker-jenkins (based on openshift jenkins... 0 [OK]
docker.io docker.io/unox/jenkins Jenkins, with the jenkins user added to th... 0 [OK]
[root@iZuf6h59snssqyqa3ka87eZ ~]# docker pull docker.io/jenkins
Using default tag: latest
Trying to pull repository docker.io/library/jenkins ...
latest: Pulling from docker.io/library/jenkins
723254a2c089: Pull complete
abe15a44e12f: Pull complete
409a28e3cc3d: Pull complete
503166935590: Pull complete
043a12c29ea4: Pull complete
303620452447: Pull complete
c61f95baa024: Pull complete
3f2018472a1f: Pull complete
a25f8a69c882: Pull complete
ef0799915650: Pull complete
d9a52178f3f2: Pull complete
21d8e85eda47: Pull complete
d1a59d3cef17: Pull complete
5736476dca56: Pull complete
677d0ef908aa: Pull complete
10d71ec5b7fd: Pull complete
768022bc0860: Pull complete
878faf994156: Pull complete
0030f731e722: Pull complete
13749a7f1512: Pull complete
Digest: sha256:b80cf491f1b4e6d490441eb54ae184f74abbd9f790495367afb7b9f1b3a7f2c9
创建数据目录并运行
[root@iZuf6h59snssqyqa3ka87eZ ~]# mkdir /data
[root@iZuf6h59snssqyqa3ka87eZ ~]# cd /data
[root@iZuf6h59snssqyqa3ka87eZ data]# docker run -d --name jenkins -p 8080:8080 -v /data/jenkins:/var/jenkins_home jenkins
5ad37d2c16d283788789282be7d0374c101cea443739b03da81ea5a0cc304104
[root@iZuf6h59snssqyqa3ka87eZ data]# docker exec -it jenkins bash
Error response from daemon: Container 5ad37d2c16d283788789282be7d0374c101cea443739b03da81ea5a0cc304104 is not running
[root@iZuf6h59snssqyqa3ka87eZ data]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5ad37d2c16d2 jenkins "/bin/tini -- /usr/lo" 2 minutes ago Exited (1) About a minute ago jenkins
[root@iZuf6h59snssqyqa3ka87eZ data]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Docker查看日志
[root@iZuf6h59snssqyqa3ka87eZ data]# docker logs jenkins
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
没有权限,修改目录权限
[root@iZuf6h59snssqyqa3ka87eZ data]# chown -R 1000 /var/jenkins_home
chown: cannot access ?.var/jenkins_home?. No such file or directory
[root@iZuf6h59snssqyqa3ka87eZ data]# chown -R 1000 /data/jenkins
[root@iZuf6h59snssqyqa3ka87eZ data]# docker start jenkins
jenkins
[root@iZuf6h59snssqyqa3ka87eZ data]# docker logs jenkins
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
Dec 27, 2017 10:05:48 AM Main deleteWinstoneTempContents
WARNING: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war
Dec 27, 2017 10:05:48 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Logging initialized @295ms
Dec 27, 2017 10:05:48 AM winstone.Logger logInternal
INFO: Beginning extraction from war file
Dec 27, 2017 10:05:49 AM org.eclipse.jetty.util.log.JavaUtilLog warn
WARNING: Empty contextPath
Dec 27, 2017 10:05:49 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: jetty-9.2.z-SNAPSHOT
Dec 27, 2017 10:05:49 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")
Dec 27, 2017 10:05:50 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started w.@56ace400{/,file:/var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
Dec 27, 2017 10:05:50 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started ServerConnector@1c80e49b{HTTP/1.1}{0.0.0.0:8080}
Dec 27, 2017 10:05:50 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started @2269ms
Dec 27, 2017 10:05:50 AM winstone.Logger logInternal
INFO: Winstone Servlet Engine v2.0 running: controlPort=disabled
Dec 27, 2017 10:05:50 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started initialization
Dec 27, 2017 10:05:50 AM jenkins.InitReactorRunner$1 onAttained
INFO: Listed all plugins
Dec 27, 2017 10:05:51 AM jenkins.InitReactorRunner$1 onAttained
INFO: Prepared all plugins
Dec 27, 2017 10:05:51 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started all plugins
Dec 27, 2017 10:05:51 AM jenkins.InitReactorRunner$1 onAttained
INFO: Augmented all extensions
Dec 27, 2017 10:05:51 AM jenkins.InitReactorRunner$1 onAttained
INFO: Loaded all jobs
Dec 27, 2017 10:05:51 AM jenkins.util.groovy.GroovyHookScript execute
INFO: Executing /var/jenkins_home/init.groovy.d/tcp-slave-agent-port.groovy
Dec 27, 2017 10:05:52 AM jenkins.InitReactorRunner$1 onAttained
INFO: Completed initialization
Dec 27, 2017 10:05:52 AM hudson.model.AsyncPeriodicWork$1 run
INFO: Started Download metadata
Dec 27, 2017 10:05:52 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@32200236: display name [Root WebApplicationContext]; startup date [Wed Dec 27 10:05:52 UTC 2017]; root of context hierarchy
Dec 27, 2017 10:05:52 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@32200236]: org.springframework.beans.factory.support.DefaultListableBeanFactory@4e3b3483
Dec 27, 2017 10:05:52 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@4e3b3483: defining beans [authenticationManager]; root of factory hierarchy
Dec 27, 2017 10:05:52 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@6492f218: display name [Root WebApplicationContext]; startup date [Wed Dec 27 10:05:52 UTC 2017]; root of context hierarchy
Dec 27, 2017 10:05:52 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@6492f218]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1ffd24f2
Dec 27, 2017 10:05:52 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1ffd24f2: defining beans [filter,legacy]; root of factory hierarchy
Dec 27, 2017 10:05:52 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:
bcd16f9176b94e7c9e8cf93a7f154540
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
查看密码,通过http://xxx.xxx.xxx.xxx:8080访问
[root@iZuf6h59snssqyqa3ka87eZ data]# cat /data/jenkins/secrets/initialAdminPassword
bcd16f9176b94e7c9e8cf93a7f154540
进入容器
[root@iZuf6h59snssqyqa3ka87eZ data]# docker exec -it jenkins bash
jenkins@5ad37d2c16d2:/$ java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-1~deb9u1-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
jenkins@5ad37d2c16d2:/$ ps -ef|grep java
jenkins 7 1 13 10:05 ? 00:00:50 java -jar /usr/share/jenkins/jenkins.war
jenkins 691 667 0 10:12 ? 00:00:00 grep java
jenkins@5ad37d2c16d2:/$ ps -ef|grep tomcat
jenkins 693 667 0 10:12 ? 00:00:00 grep tomcat
jenkins@5ad37d2c16d2:/$ cd /usr/share/jenkins/
jenkins@5ad37d2c16d2:/usr/share/jenkins$ ls
jenkins.war ref
jenkins@5ad37d2c16d2:/usr/share/jenkins$ kill -9 7
关闭进程 容器也关了
jenkins@5ad37d2c16d2:/usr/share/jenkins$ [root@iZuf6h59snssqyqa3ka87eZ data]#
[root@iZuf6h59snssqyqa3ka87eZ data]# docker exec -it jenkins bash
Error response from daemon: Container 5ad37d2c16d283788789282be7d0374c101cea443739b03da81ea5a0cc304104 is not running
重新启动
[root@iZuf6h59snssqyqa3ka87eZ data]# docker start jenkins
jenkins
[root@iZuf6h59snssqyqa3ka87eZ data]# docker exec -it jenkins bash
jenkins@5ad37d2c16d2:/$ cd /usr/share/jenkins/
jenkins@5ad37d2c16d2:/usr/share/jenkins$ ls
jenkins.war ref
jenkins@5ad37d2c16d2:~$ exit
exit
jenkins的版本是2.6.x的
Docker拉取jenkins 2.8.2
docker pull jenkins/jenkins:lts[root@iZuf6h59snssqyqa3ka87eZ data]# docker pull jenkins/jenkins:lts
Trying to pull repository docker.io/jenkins/jenkins ...
lts: Pulling from docker.io/jenkins/jenkins
Docker删除镜像
[root@iZuf6h59snssqyqa3ka87eZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/jenkins/jenkins lts 98ce3b62f77a 13 days ago 812.6 MB
docker.io/jenkins latest 5fc84ab0b7ad 2 weeks ago 808.9 MB
[root@iZuf6h59snssqyqa3ka87eZ ~]# docker rmi docker.io/jenkins
Untagged: docker.io/jenkins:latest
Untagged: docker.io/jenkins@sha256:b80cf491f1b4e6d490441eb54ae184f74abbd9f790495367afb7b9f1b3a7f2c9
[root@iZuf6h59snssqyqa3ka87eZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/jenkins/jenkins lts 98ce3b62f77a 13 days ago 812.6 MB
Jenkins配置
Jenkins主目录默认在/root/.jenkins可以设置JENKINS_HOME环境参数
编辑profile文件:vi /etc/profile
在最后加入:export JENKINS_HOME=xxxx
保存,退出后执行:source /etc/profile
JAVA_HOME=/opt/jdk1.8.0_111
JRE_HOME=$JAVA_HOME/jre
JENKINS_HOME=/data/jenkins
NEXUS_HOME=nexus-2.14.2-01
PLEXUS_NEXUS_WORK=/data/sonatype-work
M2_HOME=/opt/maven/
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$M2_HOME/bin:$NEXUS_HOME/bin:$PATH
CLASSPATH=,:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JRE_HOME PATH CLASSPATH JENKINS_HOME M2_HOME PLEXUS_NEXUS_WORK