到gitosc上,复制地址:
https://git.oschina.net/99fu/CI.git
进入到 /home/fu
git clone https://git.oschina.net/99fu/CI.git
分别进入相应的目录build镜像
![1058968-20161110132929827-2111726870.png](https://i-blog.csdnimg.cn/blog_migrate/c5e986b27b53a40ff072147042ca63d5.png)
README.md中有相应的指令:
![1058968-20161110132930155-367926956.png](https://i-blog.csdnimg.cn/blog_migrate/fc0e34f6da42d60cdc736331d482ca6e.png)
注:maven 的dockerfile可以看一下:
将自己下载好的 3.3.9的maven解压到maven目录与当前dockerfill同级,也可以打开ADD注释,通过ADD自动下载,会很慢
如果有公司内部settings.xml ,可以覆盖当前settings.xml
![1058968-20161110132930452-1207013435.png](https://i-blog.csdnimg.cn/blog_migrate/dc4bbe534c4ff7a0b6b5fed916371264.png)
运行build后,会自动构建maven中的hello项目:
![1058968-20161110132930936-1063817484.png](https://i-blog.csdnimg.cn/blog_migrate/1ad0b6f9f3a2432cbb15c86f7b7ce433.png)
启动jenkins容器,并配制jenkins:
=====================================================================================
下载jenkins镜像:
在https://hub.docker.com官网pull最新版jenkins,这里是
2.19.1
![1058968-20161110132931405-1613830136.png](https://i-blog.csdnimg.cn/blog_migrate/9f330c417fea559ffec517a2b2769beb.png)
启动jenkins:
sudo docker run -d -p 8080:8080 --name jenkins -v /usr/lib/docker:/usr/
lib
/docker -v /var/run/docker.sock:/var/run/docker.sock -v /home/fu/maven-tar:/root jenkins
说明:
-d 后台启动
-p 端口
--name 容器名称
-v /usr/lib/docker:/usr/bin/docker
-v /var/run/docker.sock:/var/run/docker.sock 把docker二进制命令给jenkins,让jenkins可以调用docker命令
-v /home/fu/maven-tar:/root 把maven挂载,jenkins可用
挂载的结果,宿主机上的maven在容器中也能查看到:
![1058968-20161110132931905-185189643.png](https://i-blog.csdnimg.cn/blog_migrate/78bcddbc6d950916c91702870258010e.png)
官方的jenkins容器说明:
![1058968-20161110132932139-573205292.png](https://i-blog.csdnimg.cn/blog_migrate/3999d3a1bafbd71445a1673e104e5114.png)
基于官方jenkins,配制一个可以执行docker的jenkins:
新建一个Dockerfile:
FROM jenkins:latest
ENV JENKINS_HOME /var/jenkins_home
ENV JENKINS_SLAVE_AGENT_PORT 50000
# Jenkins is ran with user `root`, so can operate docker
USER root
RUN apt-get update \
&& apt-get install -y sudo \
&& rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
USER jenkins
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt
我们需要赋予jenkins用户sudo权限以便能在容器内运行Docker命令。当然,也可以将jenkins用户加入到Docker组中来避免在所有Docker命令前使用‘sudo’,不过由于这个组gid的不同会造成不可移植(如Pini文中所述)。
最后两行用于处理 plugins.txt 文件中定义的插件。如果你不需要任何插件可以忽略这两行,不过1.6前推荐至少包括如下内容:
$ cat plugins.txt
scm-api:latest
git-client:latest
git:latest
greenballs:latest
plugins.txt 为空,因为新版的可以UI选择安装:
进入到Dockerfile当前目录
![1058968-20161110132932499-62694315.png](https://i-blog.csdnimg.cn/blog_migrate/1b99066e29b962c03e39d9365202ede4.png)
![1058968-20161110132932670-1742924598.png](https://i-blog.csdnimg.cn/blog_migrate/6528f07ac2d1c347c4c5a9b3f4ea8d66.png)
运行命令制作基于jenkins的镜像:
![1058968-20161110132932858-317731968.png](https://i-blog.csdnimg.cn/blog_migrate/2037364ad87acfa87d5d77be3f8868a8.png)
sudo docker build -t 99fu.cn:5000/fu/jenkins:latest .
![1058968-20161110132933577-2072186029.png](https://i-blog.csdnimg.cn/blog_migrate/89784b131cca1105f37e762384a0c013.png)
![1058968-20161110132933936-1731785750.png](https://i-blog.csdnimg.cn/blog_migrate/797d89cb3786c701cdd768503131ae5b.png)
启动容器:
sudo docker run -d -p 8080:8080 --name jenkins -v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -v /home/fu/maven-tar:/root 99fu.cn:5000/fu/jenkins:latest
或者用变量代替:
sudo docker run -d -p 8080:8080 --name jenkins -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -v /home/fu/maven-tar:/root 99fu.cn:5000/fu/jenkins:latest
我们把jenkins加入挂载目录吧,这样不小心误删,少去插件配制:
sudo docker run -d -p 8080:8080 --name jenkins -v /home/fu/jenkins_home:/var/jenkins_home -v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -v /home/fu/maven-tar:/root 99fu.cn:5000/fu/jenkins:latest
当你看日志,发现报错,这里有解答:
https://github.com/jenkinsci/docker/issues/177
报错提示:
ouch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
解决方法:
If the directory is empty:
sudo chown 1000 volume_dir
If the directory already contains files:
sudo chown -R 1000 volume_dir
![1058968-20161110132934311-600324795.png](https://i-blog.csdnimg.cn/blog_migrate/3c9a8efa1ca786df5144e87a71435cb8.png)
查看启动的容器:
![1058968-20161110132934670-1489500941.png](https://i-blog.csdnimg.cn/blog_migrate/1992ef601d776529e5503b6ace526381.png)
进入容器,查看是否能看到宿主机的镜像:
sudo docker exec -it jenkins /bin/bash
![1058968-20161110132934999-100204652.png](https://i-blog.csdnimg.cn/blog_migrate/b7f614ca783b36c8c71213f1006f06c6.png)
exit 可以退出容器
查看jenkins运行日志:
sudo docker logs jenkins
![1058968-20161110132935389-771838003.png](https://i-blog.csdnimg.cn/blog_migrate/3241c8052eda1795fe8607793b8ae2af.png)
从上面只可以看到,初始化管理密码;
配制jenkins:
在浏览器打开:http://192.168.80.147:8080
![1058968-20161110132936342-1113309451.png](https://i-blog.csdnimg.cn/blog_migrate/743fc9021283271bec8b597c7af9909d.png)
可以通过日志查看,也可在指定的文件中,把密码复制出来:
交互模式进入容器:
sudo docker exec -it jenkins /bin/bash
查看初始密码:
cat /var/jenkins_home/secrets/initialAdminPassword
![1058968-20161110132936655-563583100.png](https://i-blog.csdnimg.cn/blog_migrate/ec9ff0962db32efb203fc3e5ae162650.png)
复制密码,输入,进入
插件安装,第一种是建议安装社区使用最多的插件
第二种是自己选择安装所需的插件
![1058968-20161110132937061-973955814.png](https://i-blog.csdnimg.cn/blog_migrate/65524c3d4651d88c5d052a80c95a3650.png)
我们所须的插件有:
scm-api
plain-credentials
git-client
git
github-api
github
这里我选的建议安装:
![1058968-20161110132937670-1582452406.png](https://i-blog.csdnimg.cn/blog_migrate/8b97d3ba72a66b51335b0aaefa15688f.png)
安装完成后,配制用户:
(fu zhangxiaofu)
![1058968-20161110132938092-60366144.png](https://i-blog.csdnimg.cn/blog_migrate/f3cc6022e274a28511bc8f235a59375d.png)
![1058968-20161110132938452-1969702877.png](https://i-blog.csdnimg.cn/blog_migrate/29ee35a6c40e7e6abf96d1ab2c2b44d6.png)
![1058968-20161110132938717-1395124779.png](https://i-blog.csdnimg.cn/blog_migrate/f1ce2a14299a5d06af663169b100dcb8.png)
好啦,初始jenkins环境完成,开始配制jenkins:
进入系统配制:
![1058968-20161110132938967-1113100161.png](https://i-blog.csdnimg.cn/blog_migrate/870400d4149bcd21cae1c969c4cf7ba8.png)
我们先测试一下,在jenkins中是否可以运行docker命令:
新建-->
![1058968-20161110132939202-288195595.png](https://i-blog.csdnimg.cn/blog_migrate/ff49ef5240b5755dd59a5ddbd25f3e3a.png)
选择构建一个自由风格的软件项目:
![1058968-20161110132939483-1873890027.png](https://i-blog.csdnimg.cn/blog_migrate/4f8cfcd3482e2c8dc4f7cc9ae580783a.png)
增加构建步骤-->Excute shell:
![1058968-20161110132939952-1282014379.png](https://i-blog.csdnimg.cn/blog_migrate/ed5f88074eb9571491c8040640ff6fd7.png)
在命令框里输入“sudo docker run hello-world”
sudo docker run hello-world
保存后,点击 立即构建
![1058968-20161110132940327-585558286.png](https://i-blog.csdnimg.cn/blog_migrate/bc61e6371d3a87dd3c9897cbfed3af83.png)
点击前面的小地图,可以看到控制台输出,看到以下命令,成功!
![1058968-20161110132940764-1438302110.png](https://i-blog.csdnimg.cn/blog_migrate/fa4b055f91befd0b81f9861c6937a4bf.png)
注:
在容器中调用docker的方式
现在的问题是,jenkins是运行docker容器中,无法感知docker的存在。
在Docker中使用Docker有三种方:
DooD(Docker-outside-of-Docker)
我们需要赋予jenkins用户sudo权限以便能在容器内运行Docker命令。当然,也可以将jenkins用户加入到Docker组中来避免在所有Docker命令前使用‘sudo’,不过由于这个组gid的不同会造成不可移植
DinD(Docker in Docker)
在docker镜像中要再安装docker服务。
此时,在容器中的docker和宿主机的docker是两个不同的程序,相互没有关联,DinD并不比使用特权模式的容器安全性高,不过确实能避免使用sudo。DinD最主要的劣势是你无法重用宿主缓存的镜像(不过如果需要为测试容器提供一个与宿主隔离的干净环境,这将很有用)。
使用HTTPS与Docker后台程序通讯
jenkins配置docker插件,并且docker进行端口配置。
通过HTTPS暴露socket不需要sudo并且可以使用宿主的镜像,但因为打开了端口增加了攻击面,可以说是最不安全的
新建应用:
选择git,并复制git地址,选择分支
![1058968-20161110132941155-638560540.png](https://i-blog.csdnimg.cn/blog_migrate/4377a422de5a847e8a38505486580ef7.png)
输入Token,线上应复杂。复制路径到git上
![1058968-20161110132941499-385715234.png](https://i-blog.csdnimg.cn/blog_migrate/04fe0b7efb6f998cbb7e8d63d01a267d.png)
****
选择增加构建步骤,然后Excute shell
*****
REGISTRY_URL=192.168.80.146:5000
cp /root/apache-maven-3.3.9-bin.tar.gz $WORKSPACE/maven
sudo docker build -t $REGISTRY_URL/fu/maven:3.3.9 $WORKSPACE/maven
if sudo docker ps -a | grep -i maven ;then
sudo docker rm -f maven
fi
sudo docker create --name maven $REGISTRY_URL/fu/maven:3.3.9
sudo docker cp maven:/hello/target/hello.war $WORKSPACE/hello
sudo docker build -t $REGISTRY_URL/fu/hello:1.0 $WORKSPACE/hello
sudo docker push $REGISTRY_URL/fu/hello:1.0
if sudo docker ps -a | grep -i hello; then
sudo docker rm -f hello
fi
sudo docker run -d -p 80:8080 --name hello $REGISTRY_URL/fu/hello:1.0
- 注:须要在registry中加入REGISTRY_URL=192.168.80.146:5000 的过滤,如{ "insecure-registries":["99fu.cn:5000","192.168.80.146:5000"] }
设置registry路径
copy maven的tar包到项目maven中( $WORKSPACE为git pull下来项目中)
build maven 项目
查看当前容器,-i 忽略大小写,如果存在刚删除
然后再创建一个新的maven容器
从新创建的容器中取出maven项目下的hello的war包,到hello中
然后再构建hello项目
将hello应用push到registry中,以便别的服务可以拉取
如果hello容器已存在,须先删除,容器名字相同会使容器启动失败
启动hello容器,可从浏览器中查看更改
保存,然后设置webHooks:
点击用户名(99fu)--> 设置:
![1058968-20161110132942092-762703977.png](https://i-blog.csdnimg.cn/blog_migrate/cc22f0507e88b75b37f0f3db5603616f.png)
show api Token 查看Token:
![1058968-20161110132942405-1548454858.png](https://i-blog.csdnimg.cn/blog_migrate/6ba50bd5c35d84e21e1c69509ed21743.png)
![1058968-20161110132942702-1580105267.png](https://i-blog.csdnimg.cn/blog_migrate/f0bddf97c2e7b6fc4f2937b2ae0e093d.png)
配制gitosc上的webHooks:
http://fu:8b1a616bb9f22c01542465b81c3e5ad7@192.168.80.147:8080/job/docker-app/build?token=java-token
fu:8b1a616bb9f22c01542465b81c3e5ad7@ 从jenkins中获取
/job/docker-app/build?token=
java-token
配制完,保存,测试
![1058968-20161110132943061-933418164.png](https://i-blog.csdnimg.cn/blog_migrate/ecb601088805233b418630429641e3bb.png)
如果是外网,就可以通过修改代码,然后提交更改后,测试jenkins是否能够自动构建。
下载gitlab镜像,因为我们是本地,无法用gitosc上的勾子(webHooks)
以下是hub.docker.com 上的镜像:
docker pull sameersbn/gitlab:8.13.3
![1058968-20161110132943483-1406026390.png](https://i-blog.csdnimg.cn/blog_migrate/cee041b5ff1c2a7a3c302ed0e5dda2e0.png)
![1058968-20161110132943889-1060942872.png](https://i-blog.csdnimg.cn/blog_migrate/19d708e62def3afd8a5a1d233a852ee5.png)
![1058968-20161110132944295-1553685290.png](https://i-blog.csdnimg.cn/blog_migrate/84d79f6cee1f6c0e3dca4d9b6e26174c.png)
![1058968-20161110132944670-87395251.png](https://i-blog.csdnimg.cn/blog_migrate/c94edbae94ee2627d8c550acf6e221e3.png)
![1058968-20161110132945014-94152168.png](https://i-blog.csdnimg.cn/blog_migrate/0471885f85909ed1f4d5821f936ec17e.png)
先下载镜像:
docker pull sameersbn/gitlab:8.13.3
以上提到两种方式安装:
第一种:
第一种:
新建一个 gitlab目录,cd gitlab,
wget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml
然后运行给合命令,启动多个容器:
docker-compose up
第二种:
Step 1. Launch a postgresql container
docker run --name gitlab-postgresql -d \
--env 'DB_NAME=gitlabhq_production' \
--env 'DB_USER=gitlab' --env 'DB_PASS=password' \
--env 'DB_EXTENSION=pg_trgm' \
--volume /srv/docker/gitlab/postgresql:/var/lib/postgresql \
sameersbn/postgresql:9.5-3
Step 2. Launch a redis container
docker run --name gitlab-redis -d \
--volume /srv/docker/gitlab/redis:/var/lib/redis \
sameersbn/redis:latest
Step 3. Launch the gitlab container
docker run --name gitlab -d \
--link gitlab-postgresql:postgresql --link gitlab-redis:redisio \
--publish 10022:22 --publish 10080:80 \
--env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \
--env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \
--env 'GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string' \
--env 'GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string' \
--volume /srv/docker/gitlab/gitlab:/home/git/data \
sameersbn/gitlab:8.13.3
docker-compose.yml安装后 浏览器中:
http://192.168.80.147:10080 设置root密码
![1058968-20161110132945389-268749840.png](https://i-blog.csdnimg.cn/blog_migrate/bec75ae0c2d18f928892713e59c9e384.png)
一步步启动容器后,注册登陆用户:
![1058968-20161110132945639-860122384.png](https://i-blog.csdnimg.cn/blog_migrate/5cf4bfaf673d9daa3e3624ea3ef74d10.png)
![1058968-20161110132945874-1510077995.png](https://i-blog.csdnimg.cn/blog_migrate/7b5e4493bfa84b8ae30e08698232a722.png)
用以上的,不知为什么都是报502,连接超时,而且登陆不进去,还是换用熟悉的mysql吧!
可能是虚拟机设的内存比较下吧。会很慢,卡
![1058968-20161110132946139-141018436.png](https://i-blog.csdnimg.cn/blog_migrate/58719f5730c86460765184232e57ded2.png)
MySQL 存储:
docker run --name gitlab-mysql -d \
--env 'DB_NAME=gitlabhq_production' \
--env 'DB_USER=gitlab' --env 'DB_PASS=password' \
--volume /srv/docker/gitlab/mysql:/var/lib/mysql \
sameersbn/mysql:latest
重新用link启动,我们用mysql作为数据存储:
我们删除之前的gitlab,
postgresql 然后再运行以下执行容器命令,否则会提示容器名称重复。
docker run --name gitlab -d \
--link gitlab-mysql:mysql --link gitlab-redis:redisio \
--publish 10022:22 --publish 10080:80 \
--env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \
--env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \
--env 'GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string' \
--env 'GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string' \
--volume /srv/docker/gitlab/gitlab:/home/git/data \
sameersbn/gitlab:8.13.3
![1058968-20161110132946452-1554554179.png](https://i-blog.csdnimg.cn/blog_migrate/100665b715a81fe280c3ab0f0d89ed0c.png)
启动后:首先会让我们改一下root密码,我用的zhangxiaofu
然后登陆进去:
![1058968-20161110132946936-1102726686.png](https://i-blog.csdnimg.cn/blog_migrate/3048be7cdd96c187f27a71b7d3e21425.png)
我们新建一个项目为 app-test:
(可以看到我用的root用户)
![1058968-20161110132947217-1077840228.png](https://i-blog.csdnimg.cn/blog_migrate/79224310f6ae6d10f1ecf54de1b2856a.png)
![1058968-20161110132947483-1347252697.png](https://i-blog.csdnimg.cn/blog_migrate/48b0aef5e2df3a4879b749eaf4e08429.png)
我们上传项目到 app-test:
因为我们是新项目,进入项目文件夹:
git init
git remote add origin http://192.168.80.147:10080/root/app-test.git
git add .
git commit -m "init"
git push -u origin master
(须要多来几次,我是push啦好几次的)
打开慢的原因,之前用的vmwart 的NAT模式,内存为1G,发现特别慢
然后,停掉所有容器,然后用将内存提升到3G,网络改成啦桥接,呵呵,网一下子快啦,看来跟数据库没关系的。
验权:
![1058968-20161110132947920-409056043.png](https://i-blog.csdnimg.cn/blog_migrate/4d5c5efd07c608c6f470134e8910fc56.png)
设置作者用户名,并输入密码
![1058968-20161110132948217-814671297.png](https://i-blog.csdnimg.cn/blog_migrate/cc125924a1982847cb030936bc760a71.png)
![1058968-20161110132948592-894614366.png](https://i-blog.csdnimg.cn/blog_migrate/e4ac2536a3bfb4193970c08fcb640d6e.png)
我们遇到如下问题:
remote: GitLab: You are not allowed to push code to protected branches on this project.
To http://192.168.1.103:10080/fu/CI.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'http://192.168.1.103:10080/fu/CI.git'
![1058968-20161110132948905-519009411.png](https://i-blog.csdnimg.cn/blog_migrate/4b077494a5d6bc13e2d1425fb9ca018b.png)
解决方法:
登陆进入---> projects-->选择项目
![1058968-20161110132949186-1524844342.png](https://i-blog.csdnimg.cn/blog_migrate/a6064d6c35726e1119c49f295408bec1.png)
先择设置,Members 成员
![1058968-20161110132949545-550614252.png](https://i-blog.csdnimg.cn/blog_migrate/52474cc8656e25c31f6b8a05bdb58b22.png)
增加成员,可以搜索, 增加到哪个分支 到期时间
![1058968-20161110132950170-1898784099.png](https://i-blog.csdnimg.cn/blog_migrate/34b2fcb5b9d1a0b0d9d4f144272716f7.png)
好啦,我们再push:
![1058968-20161110132950561-955337638.png](https://i-blog.csdnimg.cn/blog_migrate/69dbe94eaf24e54206e0f24c67b452f0.png)
![1058968-20161110132950889-1290451708.png](https://i-blog.csdnimg.cn/blog_migrate/f1842c4d84b46ae26bc99e770af19c64.png)
接下来,我们要设置webHooks
fu是用启名,
79dc814d0177397b46557831252b8c62 为token
192.168.1.103:8080/job/CI/build?token=java-token
身份令牌,在jenkins中获取
Use the following URL to trigger build remotely: JENKINS_URL/job/CI/build?token=TOKEN_NAME 或者 /buildWithParameters?token=TOKEN_NAME
Optionally append &cause=Cause+Text to provide text that will be included in the recorded build cause.
![1058968-20161110132951342-2000305876.png](https://i-blog.csdnimg.cn/blog_migrate/915d6f881317a53905a825c664bc4e97.png)
提交,可以测试。
这里,我遇到啦问题。
Hook executed successfully but returned HTTP 403 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Error 403 No valid crumb was included in the request</title> </head> <body><h2>HTTP ERROR 403</h2> <p>Problem accessing /job/CI/build. Reason: <pre> No valid crumb was included in the request</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/> </body> </html>
![1058968-20161110132951858-1515463190.png](https://i-blog.csdnimg.cn/blog_migrate/be0daf80dec17aa965e243680c1250f4.png)
可以看到,请求被重置,因为在jenkins中,默认开启啦(防止跨站点请求伪造)
我们须要进入jenkins中,关闭(去掉勾选:
防止跨站点请求伪造
)
![1058968-20161110132952264-1598569506.png](https://i-blog.csdnimg.cn/blog_migrate/18de315a221f2034228865157d665c08.png)
然后再测试:
Hook executed successfully: HTTP 201
![1058968-20161110132952639-236874403.png](https://i-blog.csdnimg.cn/blog_migrate/c7a54d166f3ef675fa9c8f5d7b70da54.png)
可以看到成功啦,再看一下控制台:
![1058968-20161110132952967-454045499.png](https://i-blog.csdnimg.cn/blog_migrate/8d397d730e063dd30fc3fd22eaa4d246.png)
好啦,我们提交一下代码,看一下效果,是否能自动执行命令(注,红色的表示失败啦哦,蓝色是成功)
提交完代码,同时,就看到了jenkins执行啦!
![1058968-20161110132953342-913993638.png](https://i-blog.csdnimg.cn/blog_migrate/54af41006b1caa146d8c2dad6ac58cf8.png)
注:
jenkins 默认git pull下来的代码在:cd /var/jenkins_home/workspace/CI/
jenkins_home 环境变量
CI 为项目名
新增加一个mysql给hello项目用
docker run --name mysql -d -p 3307:3306 \
--env 'DB_NAME=xc' \
--env 'DB_USER=admin' --env 'DB_PASS=admin' \
--volume /srv/docker/mysql_data/mysql:/var/lib/mysql \
sameersbn/mysql:latest
============================> dev-springemp <============================
#jenkins docker 命令说明
--persistent String parameter
2个参数
Registry_URL
image_repository
--Registry_URL
默认值:localhost
描述:registry仓库地址
例如:139.129.21.58:443
--image_repository
描述:
应用镜像名
csphere/my-web-app
--git
https://git.oschina.net/2839543/springemp.git
--Execute Shell 4 step
# build image
docker build -t ${Registry_URL}/${image_repository}:$GIT_COMMIT $WORKSPACE/
# push image to registry
docker push ${Registry_URL}/${image_repository}:$GIT_COMMIT
# tag with latest
docker tag -f ${Registry_URL}/${image_repository}:$GIT_COMMIT ${Registry_URL}/${image_repository}:latest
# push image to registry
docker push ${Registry_URL}/${image_repository}:latest
============================> test-springemp <============================
--persistent String parameter
4个参数
Registry_URL
image_repository
image_tag
test_url
--git
https://git.oschina.net/2839543/springemp.git
--Execute Shell
#增加可执行权限
chmod u+x deploy.sh init.sh test-script.sh
#执行测试
./test-script.sh
--增加邮件通知
============================> prod-springemp <============================
--persistent String parameter
4个参数
Registry_URL
image_repository
image_tag
image_new_tag
--Execute Shell
# new tag
docker tag -f ${Registry_URL}/${image_repository}:${image_tag} ${Registry_URL}/${image_repository}:${image_new_tag}
# docker push image
docker push ${Registry_URL}/${image_repository}:${image_new_tag}