1.dokcer 私有仓库搭建
docker pull registry
docker run -di --name=registry -p 5000:5000 registry
http://192.168.33.11:5000/v2/_catalog //访问私有仓库
配置/etc/docker/daemon.json文件 添加信任地址
"insecure-registries": [192.168.33.11:5000] # 设置docker的私有仓库地址
docker tag jdk1.8 192.168.33.11:9000/jdk1.8 //准备
docker push jdk1.8 192.168.33.11:9000/jdk1.8 //上传
2.docker maven插件
2.1修改宿主机的配置,让其可以远程访问
vi /lib/systemd/system/docker.service
添加的内容为
-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
2.2 刷新配置,重启服务
systemctl daemon-reload
systemctl restart docker
2.3 在工程pom添加配置
<build>
<finalName>app</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- docker的maven插件,官网:https://github.com/spotify/docker-maven-plugin -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>192.168.184.141:5000/${project.artifactId}:${project.version}</imageName>
<baseImage>jdk1.8</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<dockerHost>http://192.168.184.141:2375</dockerHost>
</configuration>
</plugin>
</plugins>
</build>
ip是需要自己改的,并且需要准备一个jdk1.8的镜像,镜像名= jdk1.8 以上配置会自动生成Dockerfile 生成的对应的文件配置如下
2.5构建镜像
mvn docker:build
也可以在构建命令的同时把镜像推送到register仓库,,命令为
mvn docker:build -DpushImage
3.可持续化集成、docker监控
3.1 gogs安装配置 --私有仓库
docker pull gogs/gogs
docker run -di --name=gogs -p 10022:22 -p 3000:3000 -v /var/gogsdata:/data gogs/gogs
http://192.168.33.11:3000
3.2 jenkins --持续化集成工具
rpm -ivh .rpm //安装
vi /etc/sysconfig/jenkins //修改用户名和端口
systemctl start jenkins //启动jenkins
3.3 rancher--基于docker的图形化管理工具
(1)安装
docker pull rancher/server
docker run -di --name=rancher -p 9001:8080 rancher/server
//配置步骤
环境配置
主机配置
应用配置-添加服务
//扩容、缩容
扩容:通过url触发容器的扩容
缩容:类似扩容
3.4 使用InfluxDB+cAdvisor+Grafana配置Docker监控
参考:https://www.linuxidc.com/Linux/2017-11/148351.htm
//influxdb 数据库
docker pull tutum/influxdb
docker run -di --name=influxsrv -p 8083:8083 -p 8086:8086 tutum/influxdb //8083:web访问端口 8086:数据写入端口
http://192.168.33.11:8083/
//创建数据库
create database "cadvisor"
//创建用户
CREATE USER "cadvisor" WITH PASSWORD "cadvisor"
//用户授权
grant all privileges on "cadvisor" to "cadvisor"
//授予读写权限
grant WRITE on "cadvisor" to "cadvisor"
grant READ on "cadvisor" to "cadvisor"
//cAdvisor 监控容器的工具
docker pull google/cadvisor
docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro -p 8080:8080 --detach=true --link influxsrv:influxsrv --name=cadvisor google/cadvisor -storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_host=influxsrv:8086
http://192.168.33.11:8080/containers/
//Grafana 可视化工具,读取influxdb数据,还可以进行预警
docker pull grafana/grafana
docker run -d -p 3001:3000 -e INFLUXDB_HOST=influxsrv -e INFLUXDB_PORT=8086 -e INFLUXDB_NAME=cadvisor -e INFLUXDB_USER=cadvisor -e INFLUXDB_PASS=cadvisor --link influxsrv:influxsrv --name=grafana grafana/grafana
http://192.168.33.11:3001
操作步骤:
添加数据源
新增仪表盘
预警通知设置
网友评论