基于jenkins自动打包并部署docker环境
一、实验环境
git 192.168.200.71
jenkins 192.168.200.72
docker 192.168.200.73
[root@web ~]# systemctl stop firewalld
[root@web ~]# iptables -F
[root@web ~]# setenforce 0
二、安装docker-ce
1、安装依赖环境
[root@jenkins ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
2、准备镜像源
[root@jenkins ~]# curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
3、安装docker-ce
[root@jenkins ~]# yum -y install docker-ce
4.启动docker
[root@docker ~]# docker version
针对Docker客户端版本大于 1.10.0 的用户
您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
{
"registry-mirrors": ["https://你的阿里云镜像加速器.com"]
}
[root@docker ~]# systemctl restart docker #重启服务
[root@web ~]# ls
anaconda-ks.cfg
centos-7-x86_64.tar.gz
将镜像导入到docker容器中
[root@web ~]# cat centos-7-x86_64.tar.gz | docker import - centos:7
sha256:f6eb67031cab4819c9456581efbba632e5ba3b5339090ee484e60137f264c01f
[root@web ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 f6eb67031cab 41 seconds ago 589MB
[root@web ~]# cd docker-tomcat/
apache-tomcat-8.5.16.tar.gz jdk-8u191-linux-x64.tar.gz
MAINTAINER from crushlinux <crushlinux@163.com>
ADD ./apache-tomcat-8.5.16.tar.gz /usr/local/
ADD ./jdk-8u191-linux-x64.tar.gz /usr/local
ENV JAVA_HOME /usr/local/jdk1.8.0_191
ENV PATH $JAVA_HOME/bin:$PATH
ENTRYPOINT /usr/local/apache-tomcat-8.5.16/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.16/logs/catalina.out
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat v1 f46aebf0e2d2 About a minute ago 999MB
centos 7 f6eb67031cab 15 minutes ago 589MB
配置git
git@192.168.200.71:/home/git/probe.git
选择Build
target/dist/**/*
/data
scp 192.168.200.72:/var/lib/jenkins/workspace/probe/web/target/probe.war /data/ docker run-itd--name tomcat-test-p 8090:8080-v /data:/usr/local/apache-tomcat-8.5.16/webapps tomcat:v1