使用最新的官方镜像jenkins/jenkins
第一次使用的docker部署jenkins的时候,出现了两个问题:
1、因为用户权限问题挂载/home/jenkins/data到/var/jenkins_home挂载不了。后面通过修改data目录的所属用户可以解决,即在容器下查询用户id(1000),然后把data改成同样的用户id
2、即便挂载docker命名和docker.sock,也修改了相应的权限,仍存在libltdl7没有权限读取。当然好像也不影响使用,只是在容器里面执行docker info的时候,会报无法读取libltdl7.so的信息。
于是查找资料在jenkins/jenkins基础上再建一个Jenkins镜像。
编辑Dockerfile
FROM jenkins/jenkins USER root #清除了基础镜像设置的源,切换成阿里云的jessie源 RUN echo ‘‘ > /etc/apt/sources.list.d/jessie-backports.list && echo "deb http://mirrors.aliyun.com/debian jessie main contrib non-free" > /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list && echo "deb http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list #更新源并安装缺少的包 RUN apt-get update && apt-get install -y libltdl7 ARG dockerGid=999 RUN echo "docker:x:${dockerGid}:jenkins" >> /etc/group USER jenkins # 安装 docker-compose --- 挂载宿主机上的就可以了 # RUN curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose # RUN chmod +x /usr/local/bin/docker-compose
开启容器,挂载maven
#!/bin/bash docker run --name jenkins -p 8008:8080 -p 50000:50000 --add-host=‘centos6.5:192.168.0.8‘ \ # 增加额外host,这个是gitlab的ip -v /opt/maven3.5.2:/var/maven3.5.2 -v /opt/maven_jar:/var/maven_jar -v /home/jenkins/settings.xml:/var/jenkins_home/.m2/settings.xml -v /etc/localtime:/etc/localtime:ro -v /home/jenkins/data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -v $(which docker-compose):/usr/local/bin/docker-compose -d com.jay.myjenkins:latest
settings.xml以及maven需要在jenkins配置里配置一下。
原文地址:https://www.cnblogs.com/jay763190097/p/8305911.html
时间: 2024-11-05 15:51:25