实战环境windows、mac、linux等系统,只要装了docker服务都可以作为实战环境,我用的是ubuntu16,安装的docker版本是:17.03.2-ce;准备文件映射路径jenkins的容器启动后,重要的文件我们希望能保存在当前电脑,否则容器被损坏或者删除后就找不回这些文件了,因此要在当前电脑上准备一个目录作为文件映射,注意文件夹权限问题,我这边准备的本机目录是/usr/local/work/jenkins,并且执行了chmod 777 /usr/local/work/jenkins以确保docker进程有权限读写此目录;启动容器在控制台执行以下命令,docker会去hub.docker.com下载最新的jenkins官方镜像,然后启动一个名为j01的容器,并且将容器的8080和50000端口直接映射到本机的8080和50000端口:docker run -p 8080:8080 -p 50000:50000 -v /usr/local/work/jenkins:/var/jenkins_home --name j01 -idt jenkins 执行命令docker logs -f j01查看容器的控制台日志,看到如下信息表示jenkins服务启动成功:Dec 31, 2017 6:29:24 AM jenkins.install.SetupWizard initINFO: ***************************************************************************************************************************************************************************************Jenkins initial setup is required. An admin user has been created and a password generated.Please use the following password to proceed to installation:f0f2e35d549f49b486b0ca2bdf3756d6This may also be found at: /var/jenkins_home/secrets/initialAdminPassword***************************************************************************************************************************************************************************************Dec 31, 2017 6:29:29 AM hudson.model.UpdateSite updateDataINFO: Obtained the latest update center data file for UpdateSource defaultDec 31, 2017 6:29:30 AM hudson.model.DownloadService$Downloadable loadINFO: Obtained the updated data file for hudson.tasks.Maven.MavenInstallerDec 31, 2017 6:29:30 AM hudson.model.UpdateSite updateDataINFO: Obtained the latest update center data file for UpdateSource defaultDec 31, 2017 6:29:30 AM hudson.WebAppMain$3 runINFO: Jenkins is fully up and running--> setting agent port for jnlp--> setting agent port for jnlp... doneDec 31, 2017 6:29:33 AM hudson.model.DownloadService$Downloadable loadINFO: Obtained the updated data file for hudson.tools.JDKInstallerDec 31, 2017 6:29:33 AM hudson.model.AsyncPeriodicWork$1 runINFO: Finished Download metadata. 11,856 ms 访问服务我的LINUX电脑IP是192.168.119.155,在浏览器输入http://192.168.119.155:8080,即可访问到jenkins的服务,由于密码还没有设置,将会看到下图信息: 这里写图片描述页面提示密码文件的位置:/var/jenkins_home/secrets/initialAdminPassword,由于我们已经将/var/jenkins_home目录映射到本机的/usr/local/work/jenkins目录,所以密码文件在当前电脑的位置是:/usr/local/work/jenkins/secrets/initialAdminPassword;打开此文件后发现只有一行内容,复制后粘贴到页面唯一的输入框中,再点击右下角的”Continue”按钮;