使用Jenkins docker镜像运行Jenkins服务

需求

使用docker技术管理Jenkins服务器。避免多次部署需要重复安装的重复工作,且可以方便迁移到新的服务器。

Jenkins docker镜像

https://hub.docker.com/_/jenkins/

Official Jenkins Docker image

拉取镜像:

docker pull jenkins

使用镜像:

docker run --name myjenkins -p 8080:8080 -p 50000:50000 -v /var/jenkins_home jenkins

docker客户端安装

http://www.cnblogs.com/xishuai/p/ubuntu-install-docker.html

安装命令:

更新程序包索引,以及添加使用 HTTPS 传输的软件包以及 CA 证书。

$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates

添加 Docker 官方软件源的 GPG 密钥(验证所下载软件包的合法性)。

$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

需要向source.list中添加 Docker 软件源,下表列出了不同的 Ubuntu 和 Debian 版本对应的 APT 源。

操作系统版本REPO
Precise 12.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-precise main
Trusty 14.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-trusty main
Xenial 16.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-xenial main
Debian 7 Wheezy deb https://apt.dockerproject.org/repo debian-wheezy main
Debian 8 Jessie deb https://apt.dockerproject.org/repo debian-jessie main
Debian Stretch/Sid deb https://apt.dockerproject.org/repo debian-stretch main

用下面的命令将 APT 源添加到 source.list(将其中的 <REPO> 替换为上表的值):

$ echo "<REPO>" | sudo tee /etc/apt/sources.list.d/docker.list

添加成功后,更新 apt 软件包缓存。

$ sudo apt-get update

在一切准备就绪后,就可以安装最新版本的 Docker 了,软件包名称为 docker-engine

$ sudo apt-get install docker-engine

如果系统中存在旧版本的 Docker (lxc-docker, docker.io),会提示是否先删除,选择是即可。

设置国内镜像源

使用docker pull jenkins, 发现运行速度非常慢。

将镜像源切换为国内地址。

https://www.daocloud.io/mirror#accelerator-doc

Linux

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

该脚本可以将 --registry-mirror 加入到你的 Docker 配置文件 /etc/docker/daemon.json 中。适用于 Ubuntu14.04、Debian、CentOS6 、CentOS7、Fedora、Arch Linux、openSUSE Leap 42.1,其他版本可能有细微不同。更多详情请访问文档。

运行效果

运行:

docker run --name myjenkins -p 8080:8080 -p 50000:50000 -v /var/jenkins_home jenkins

控制台截图:

 访问Jenkins网站:

用了docker就是So Easy

原文地址:https://www.cnblogs.com/lightsong/p/9867944.html