环境

centos 7

jdk1.7

1查询jenkins

[root@station /]# docker search jenkins

2安装jenkens

[root@station /]# docker pull  jenkins
[root@VM_0_3_centos /]# docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
xiaojinlu/java                         latest              2dc42accd0fa        2 days ago          700 MB
127.0.0.1:5000/xiaojinlu/java          latest              2dc42accd0fa        2 days ago          700 MB
<none>                                 <none>              e4b867db0a43        3 days ago          538 MB
docker.io/hello-world                  latest              4ab4c602aa5e        4 days ago          1.84 kB
docker.io/jenkinsci/jenkins            latest              99ab31398cbc        9 days ago          701 MB

[root@VM_0_3_centos /]# docker run -d -u root  -p 8080:8080  -v /jenkins:/var/jenkins_home --name 99ab31398cbc  jenkins

我们通过-d  来后台启动,-p 来做端口映射, -v  来做目录映射   其中/var/jenkins  是jenkins的根目录,/jenkins是宿主机目录

当容器停止时/jenkins不会被清除,便于数据备份,体现了数据与程序分离的原则,通过--name 来指定Jenkins的名称,便于查找。

3查询日志

[root@station /]# docker logs -f jenkins

4进入容器

docker exec -it jenkins /bin/bash

5  查看密码

$ cat  /var/jenkins_home/secrets/initialAdminPassword

 

备注遇到问题

/usr/bin/docker-current: Error response from daemon: Conflict. The container name "/99ab31398cbc" is already in use by container bc7664d8f6bd6b43dd095ab9d4378b722be1d1eab2a68b47e4bbcd5748e28471. You have to remove (or rename) that container to be able to reuse that name..
解决办法(添加 -u  roo他命令)

docker run -d -u root  -p 8080:8080  -v /jenkins:/var/jenkins_home --name 99ab31398cbc  jenkinsci/jenkins

启动前先删除容器

[root@VM_0_3_centos /]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS               NAMES
7389036b5fa3        jenkinsci/jenkins   "/sbin/tini -- /us..."   17 minutes ago      Exited (130) 2 minutes ago                       99ab31398cbc
33f00d74e6eb        2dc42accd0fa        "/bin/bash"              47 hours ago        Exited (1) 46 hours ago                          heuristic_williams
[root@VM_0_3_centos /]# docker rm 33f00d74e6eb

[root@VM_0_3_centos /]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                    PORTS               NAMES

[root@VM_0_3_centos /]# docker run -d -u root  -p 8080:8080  -v /jenkins:/var/jenkins_home --name 99ab31398cbc  jenkinsci/jenkins


无法更新插件设置,进入http://:8080/pluginManager/advanced,修改为http://updates.jenkins.io/update-center.json

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐