因公司项目的要求,让我在今天把docker和jenkins搭建起来,我在搭建成功后,把其中遇到的问题和解决办法记录下来分享给大家. 系统:centos 6.5(64位) 1.先查看内核是否是3.10 uname -r 如果不是3.10的执行下面的命令: rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org rpm -ivh http://www.elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm 安装kernel-lt(lt=long-term) yum --enablerepo=elrepo-kernel install kernel-lt kernel-lt-headers -y 或者安装kernel-ml(ml=mainline) yum --enablerepo=elrepo-kernel install kernel-ml kernel-ml-headers -y ps:请自己根据需要来选择上面的内核. 编辑grub.conf文件,修改Grub引导顺序 vi /etc/grub.conf
确认刚安装好的内核在哪个位置,然后设置default值(从0开始),一般新安装的内核在第一个位置.所以设置default=0 2.安装docker wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -ivh epel-release-6-8.noarch.rpm yum -y install docker-io* service docker start chkconfig docker on 如果启动docker出现如下错误: /usr/bin/docker: relocation error: /usr/bin/docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference 请执行下面的命令: yum install device-mapper-event-libs 如果没问题了的话,我们来验证下docker,执行下面的命令: docker --version Docker version 1.7.1, build 786b29d/1.7.1 我这里显示的1.7.1的版本.好了,下面我们可以用docker来安装jenkins了. 3.docker安装jenkins docker pull jenkinsci/jenkins ps:因为我们项目指定了要这个 如果出现下面的错误: unable to get remote tags: Get https://registry-1.docker.io/v1/repositories/library/jenkins/tags: dial tcp 218.93.250.18:443: connection timed out 请执行: dig index.docker.io +noall +answer +nocomments 我这里看到有3个ip,如下: ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.5 <<>> index.docker.io +noall +answer +nocomments ;; global options: +cmd index.docker.io. 251 IN CNAME elb-io.us-east-1.aws.dckr.io. elb-io.us-east-1.aws.dckr.io. 530 IN CNAME us-east-1-elbio-rm5bon1qaeo4-623296237.us-east-1.elb.amazonaws.com. us-east-1-elbio-rm5bon1qaeo4-623296237.us-east-1.elb.amazonaws.com. 31 IN A 54.164.250.255 us-east-1-elbio-rm5bon1qaeo4-623296237.us-east-1.elb.amazonaws.com. 31 IN A 54.152.78.181 us-east-1-elbio-rm5bon1qaeo4-623296237.us-east-1.elb.amazonaws.com. 31 IN A 52.0.10.162 我随便选了个ip加到hosts里 echo '54.208.179.150 registry-1.docker.io' >> /etc/hosts 然后再执行 docker pull jenkinsci/jenkins 如果下载成功了的话,我们来验证下: docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE jenkinsci/jenkins latest bbb3fdd65bef 3 days ago 882.6 MB ps:docker images 指令可以查询目前已pull回來的image的清单及简易的资讯內容. 好了,然后我们来启动jenkins: docker run -d -p 8080:8080 jenkinsci/jenkins 如果启动的时候报以下错误: Cannot start container f12cdd095c6fcfc759e7986276b49d3647e02cc50e55ce9cf1559ed249617281: iptables failed: iptables -t nat -A DOCKER -p tcp -d 0/0 --dport 8080 -j DNAT --to-destination 172.17.0.8:8080 ! -i docker0: iptables: No chain/target/match by that name.\n (exit status 1) 解决办法: cp /etc/sysconfig/iptables /etc/sysconfig/iptables.bak vi /etc/sysconfig/iptables
然后保存退出并重启iptables.再来启动jenkins: docker run -d -p 8080:8080 jenkinsci/jenkins 然后在浏览器里进行验证: http://ip:8080 如果可以看到下图,那就表示你jenkins启动成功了. 好了,docker+jenkins的配置就到这里了,剩下的请自己去探索研究了. (责任编辑:IT) |