Docker-swarm Health、Secret、Stack

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

帮助
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值