Docker部署jenkins
https://www.cnblogs.com/hiyong/p/14405561.html
1. 下载Image
[root@server /]# docker pull jenkins/jenkins Using default tag: latest latest: Pulling from jenkins/jenkins 3192219afd04: Already exists 17c160265e75: Already exists cc4fe40d0e61: Already exists 9d647f502a07: Already exists d108b8c498aa: Already exists 1bfe918b8aa5: Already exists dafa1a7c0751: Already exists c69d355c63ac: Pull complete b15898bb1800: Pull complete a51ccfc981f7: Pull complete 49f46bd4bf74: Pull complete efa670fd97de: Pull complete 1565294bcba3: Pull complete 4c51bcfbed1e: Pull complete 49f4fafbfbf2: Pull complete 28a75541fa5f: Pull complete c3c03c2d5564: Pull complete ace64d1af7cf: Pull complete f1960af3b8ab: Pull complete 6fd1a5a6d017: Pull complete Digest: sha256:e4630b9084110ad05b4b51f5131d62161881216d60433d1f2074d522c3dcd6dc Status: Downloaded newer image for jenkins/jenkins:latest docker.io/jenkins/jenkins:latest
2. 创建docker的文件影射卷,用户数据存储
[root@server tmp]# docker volume create jenkins_test [root@server tmp]# docker volume inspect jenkins_test [ { "CreatedAt": "2020-07-18T10:49:17+08:00", "Driver": "local", "Labels": {}, "Mountpoint": "/var/lib/docker/volumes/jenkins_test/_data", "Name": "jenkins_test", "Options": {}, "Scope": "local" } ] [root@server tmp]#
3.创建container
[root@server /]# docker run --name=jenkins -d -p 8080:8080 -p 50000:50000 -v jenkins_test:/var/jenkins_home jenkins/jenkins c7fb87aec99402febd95edddda5cf1dc7ad15437f674bf71a09692d93369ccb9 [root@server /]# [root@server /]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c7fb87aec994 jenkins/jenkins "/sbin/tini -- /usr/…" 9 minutes ago Up 9 minutes 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp jenkins
浏览器输入电脑IP地址+端口号:http://192.168.2.188:8080/
查看密码有两种方法:
#方法1:cat docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword #方法2: 将文件从容器复制到服务器再查看 [root@localhost jenkins_home]# docker cp jenkins:/jenkins_test/secrets/initialAdminPassword secrets/initialAdminPassword invalid output path: directory "/var/jenkins_home/secrets" does not exist 后改为如下命令成功,应该是权限的问题 [root@localhost jenkins_home]# docker cp jenkins:/var/jenkins_home/secrets secrets/ Preparing to copy... Copying from container - 512B Copying from container - 1.024kB Copying from container - 1.057kB Copying from container - 1.536kB Copying from container - 2.048kB Copying from container - 2.08kB Copying from container - 2.56kB Copying from container - 3.072kB Copying from container - 3.328kB Copying from container - 3.584kB Copying from container - 4.096kB Successfully copied 4.608kB to /var/jenkins_home/secrets/ [root@localhost jenkins_home]# ls -a . .. secrets
输入密码后开始配置: