1.Health
可以检测容器的健康状态
启动一个容器
[root@node1 ~]# docker run -dit --name test 192.168.64.10:5000/httpd
node1下载一个nginx镜像
打标签并上传到私有仓库
[root@node1 ~]# docker pull nginx
[root@node1 ~]# docker tag nginx:latest 192.168.64.10:5000/nginx
[root@node1 ~]# docker push 192.168.64.10:5000/nginx
从node2下载一个centos7镜像
打标签并上传到私有仓库
[root@node2 ~]# docker pull centos:7
[root@node2 ~]# docker tag centos:7 192.168.64.10:5000/centos7
[root@node2 ~]# docker push 192.168.64.10:5000/centos7
启动一个nginx容器并进入
[root@node1 ~]# docker run -dit --name test1 nginx
[root@node1 ~]# docker exec -it test1 bash
[root@node1 ~]# docker rm -f test1
在node2基于centos镜像写一个Dockerfile
先在node1模拟安装nginx成功在基于镜像安装
阿里云网站https://developer.aliyun.com/mirror/
安装epel源、安装nginx
[root@node1 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@node1 ~]# yum -y install nginx
让nginx服务一直在前台启动
[root@node1 ~]# vim /etc/nginx/nginx.conf
第二种方法启动的时候传参
[root@node1 ~]# nginx -g "daemon off;"
在node2写Dockerfile文件
写一个静态页面一会传进dockerfile文件
[root@node2 mynginx]# vim index.html
Dockerfile文件
构建
[root@node2 mynginx]# docker build -t 192.168.64.10:5000/mynginx .
启动nginx容器
[root@node2 mynginx]# docker run -dit --name test2 -p 80 192.168.64.10:5000/mynginx
测试成功就会返回我们传的静态页面
[root@node2 mynginx]# curl http://192.168.64.20:32770
删除test2容器‘
[root@node2 mynginx]# docker rm -f test2
把镜像上传到私有仓库
[root@node2 mynginx]# docker push 192.168.64.10:5000/mynginx
启动一个容器并且实现健康检查
以下是对于一个单机的容器来做
[root@node2 mynginx]# docker run -dit --name test --health-cmd "curl -f http://localhost/ ||exit 1" --health-timeout 5s --health-interval 8s -p 80 192.168.64.10:5000/mynginx
–health-cmd: 运行一个命令检测容器的健康
–health-interval : 间隔时间
–health-timeout :超时时间
–health-retries 3: 测试三次
检测一个不存在的页面
[root@node2 mynginx]# docker run -dit --name test1 --health-cmd "curl -f http://localhost/no ||exit 1" --health-timeout 5s --health-interval 8s -p 80 192.168.64.10:5000/mynginx
对于swarm集群来做健康检查
查看私有仓库的镜像
[root@node1 ~]# curl node1:5000/v2/_catalog
启动容器并检测
[root@node1 ~]# docker service create --name test1 --health-cmd "curl -f http://locathost/ || exit 1" --health-timeout 5s --health-interval 10s --health-retries 3 192.168.64.10:5000/mynginx
模拟一个错误的页面
[root@node1 ~]# docker service create --name test1 --health-cmd "curl -f http://locathost/no || exit 1" --health-timeout 5s --health-interval 10s --health-retries 3 192.168.64.10:5000/mynginx
不断地尝试如果一台几点起不来就会换一台容器启动知道容器正常启动
2.Secret密码管理
先下载一个mysql镜像
[root@node1 ~]# docker pull mysql:5.7
帮助