这是我们使用自建 docker swarm 集群后在部署时遇到的一个问题,使用 docker service update 命令更新服务时,

docker service update -d=false --force service_name

在更新的过程中服务有短暂的时间不能访问。

该服务中运行的是 asp.net core web api ,所使用的 Dockerfile 如下:

FROM microsoft/aspnetcore:1.1.2
ARG PROJECT
WORKDIR /app
COPY ${PROJECT}/publish .
RUN echo "dotnet ${PROJECT}.dll --urls http://*:80" > run.sh

通过在服务更新期间在另外一个容器中运行下面的 curl 命令捕捉这个问题:

while true;do curl -sSf -w '%{http_code}' cloud_api/alive;sleep 2;done

service update 期间不能访问所更新的服务时,curl 会出现下面的输出:

curl: (7) Failed to connect to cloud_api port 80: Connection refused
000

怀疑是容器启动后,asp.net core web api 站点没有立即开始工作,dotnet 命令启动站点也需要一定的时间。

针对这个怀疑点,在 Dockcefile 中添加 HEALTHCHECK 指令,这样可以让 docker 在容器启动后对容器内应用进行健康检查,检查通过才将容器投入使用。

HEALTHCHECK --interval=5s --timeout=20s \
CMD curl -fs localhost/alive || exit 1

注:localhost/alive 是容器内应用实现的一个健康检查 url 。

添加 HEALTHCHECK 后重新构建镜像并部署,执行 service update 命令问题没有出现,搞定!

docker swarm:执行 service update 过程中服务短暂不能访问的问题的更多相关文章

  1. 在执行xp_cmdshell的过程中出错,调用'LogonUserW'失败,错误代码:'1909'

    在上篇文章Could not obtain information about Windows NT group/user 'xxxx\xxxx', error code 0x5里面,我介绍了SQL ...

  2. 当用GridView导出Execl的时候,会发生只能在执行 Render() 的过程中调用 RegisterForEventValidation的错误

    当用GridView导出Execl的时候,会发生只能在执行 Render() 的过程中调用 RegisterForEventValidation的错误提示. 有两种方法可以解决以上问题: 1.修改we ...

  3. 只能在执行 Render() 的过程中调用 RegisterForEventValidation(RegisterForEventValidation can only be called during Render();

    只能在执行 Render() 的过程中调用 RegisterForEventValidation(RegisterForEventValidation can only be called durin ...

  4. "只能在执行Render()的过程中调用RegisterForEventValidation" 解决方案

    开发中遇到令人蛋疼的问题: 只能在执行Render()的过程中调用RegisterForEventValidation 当出现的异常的提示: 异常详细信息: System.InvalidOperati ...

  5. 只能在执行 Render() 的过程中调用 RegisterForEventValidation

    当用GridView导出Execl的时候,会发生只能在执行 Render() 的过程中调用 RegisterForEventValidation的错误提示.有两种方法可以解决以上问题: 1.修改web ...

  6. Error 之 只能在执行Render() 的过程中调用 RegisterForEventValidation;

    在实现"将GridView中的数据导出到Excel中"的时候出现了如下错误: 用户代码未处理 InvalidOperationException 只能在执行 Render() 的过 ...

  7. C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation

    C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation 后台添加以下方法:/// <summa ...

  8. 只能在执行Render() 的过程中调用 RegisterForEventValidation;

    October 17, 2008  3:28 PMMarch 29, 2013  8:28 PM Aillo 编程   0 Comments 在实现"将GridView中的数据导出到Exce ...

  9. 问题:只能在执行 Render() 的过程中调用 RegisterForEventValidation;结果:只能在执行 Render() 的过程中调用 RegisterForEventValidation

    只能在执行 Render() 的过程中调用 RegisterForEventValidation 当在导出Execl或Word的时候,会发生只能在执行 Render() 的过程中调用 Register ...

随机推荐

  1. Mysql INSERT、REPLACE、UPDATE的区别

    用于操作数据库的SQL一般分为两种,一种是查询语句,也就是我们所说的SELECT语句,另外一种就是更新语句,也叫做数据操作语句.言外之意,就是对数据进行修改.在标准的SQL中有3个语句,它们是INSE ...

  2. Asp.Net MVC4中的全局过滤器

    可以对整个项目进行全局监控. 新建一个MVC4项目,可以在global.asax文件中看到如下代码:  FilterConfig.RegisterGlobalFilters(GlobalFilters ...

  3. vue弹框,删除元素

    1.效果 2.index.html <!DOCTYPE html> <html lang="en"> <head> <meta chars ...

  4. 每日英语:These Gadgets Aim To Put Some Teeth Into The Internet Of Things

    What the world needs now is a Web-enabled toothbrush. That part is clear to several oral-hygiene com ...

  5. [INS-20802] Oracle Net Configuration Assistant failed

    [INS-20802] Oracle Net Configuration Assistant failed.在安装Oracle 11g R2时出现了该错误提示.以前安装的时候没有碰到过类似的错误.原来 ...

  6. C语言 · 2n皇后问题

    基础练习 2n皇后问题   时间限制:1.0s   内存限制:512.0MB        锦囊1 搜索算法. 锦囊2 先搜索n皇后的解,在拼凑成2n皇后的解. 问题描述 给定一个n*n的棋盘,棋盘中 ...

  7. 使用Fidder将生成环境代码映射到本地(文件夹)

    匹配生产URL正则表达式 regex:http://www.a.com/statics/js/(.*) 本地路径配置 D:\web\statics\js\$1

  8. android ROM刷机updater-script单刷补丁包脚本

    ui_print(""); ui_print("-------------------------"); ui_print(" Let's Go &q ...

  9. 点云PCL中小细节

    计算点与点之间的距离的平局距离 double computeCloudResolution (const pcl::PointCloud<PointType>::ConstPtr & ...

  10. Java知多少(27)继承的概念与实现

    继承是类与类之间的关系,是一个很简单很直观的概念,与现实世界中的继承(例如儿子继承父亲财产)类似. 继承可以理解为一个类从另一个类获取方法和属性的过程.如果类B继承于类A,那么B就拥有A的方法和属性. ...