在使用Jenkins和Docker进行测试时,我不完全了解我的容器和图像正在发生什么。
首先,我从jenkins / jenkins:tls构建了我的第一个Docker容器
docker run --name myjenkins -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
我从jenkins安装中收到了典型的消息,初始密码为:
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:
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
我完成了安装过程,并且和Jenkins玩了一段时间。一切正常。
我的误会是从一开始就重复这个过程。我删除了容器,并再次构建了相同的容器。
docker container stop myjenkins <- Stop container
docker container rm myjenkins <- Remove myjenkins container
docker image rm 95bf220e341a <- Remove jenkins/jenkins image
docker run --name myjenkins -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
但是在这种情况下,詹金斯第二次没有给我显示新的初始密码:
Jun 18, 2019 7:43:17 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@83bb567: defining beans [authenticationManager]; root of factory hierarchy
<-- I was expecting the message just here -->
Jun 18, 2019 7:43:17 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@5bfdcaf3: display name [Root WebApplicationContext]; startup date [Tue Jun 18 19:43:17 UTC 2019]; root of context hierarchy
Jun 18, 2019 7:43:17 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@5bfdcaf3]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1f98db0a
Jun 18, 2019 7:43:17 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1f98db0a: defining beans [filter,legacy]; root of factory hierarchy
Jun 18, 2019 7:43:18 PM jenkins.InitReactorRunner$1 onAttained
INFO: Completed initialization
Jun 18, 2019 7:43:19 PM hudson.WebAppMain$3 run
INFO: Jenkins is fully up and running
我尝试使用docker system prune -a
,但没有任何改变。每次尝试重建容器时,都无法再次获得“初始管理员密码”消息。
发生了什么事?如果我删除一个容器.. Docker / Jenkins如何知道这不是我第一次尝试安装jenkins?
答案 0 :(得分:1)
-v jenkins_home:/var/jenkins_home
您正在将该目录映射到某个位置,以便Docker映像(希望)是不变的。重新创建它没有区别-如果您不删除该文件夹,则下次启动图像时,Jenkins的配置数据将保持不变。
此外,这意味着您的bootstrap pwd应该在docker主机上可用:
jenkins_home/secrets/initialAdminPassword