Docker Swarm – 不要在 entrypoint 成功时重新启动服务

huangapple go评论48阅读模式
英文:

Docker Swarm - don't restart service on entrypoint success

问题

在尝试在Docker Swarm上部署我的应用程序时,我有两个服务:NGINX用于提供静态文件,app用于编译一些静态文件。为了运行静态文件编译,我在Compose文件中使用entrypoint。

docker-compose.yml:

version: "3.9"

services:
  nginx:
    image: nginx
    healthcheck:
      test: curl --fail -s http://localhost:80/lib/tether/examples/viewport/index.html || exit 1
      interval: 1m
      timeout: 5s
      retries: 3
    volumes:
      - /www:/usr/share/nginx/html/
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - node.role == manager
    ports:
      - "8000:80"
    depends_on:
      - client

  client:
    image: my-client-image:latest
    restart: "no"
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - node.role == manager
    volumes:
      - /www:/app/www
    entrypoint: /entrypoint.sh

entrypoint.sh:

./node_modules/.bin/gulp compilescss

我尝试在我的服务中添加了 restart: "no",但是服务在entrypoint完成后仍然重新启动。

英文:

When trying to deploy my app on Docker swarm I have two services: NGINX to serve static files and app to compile some static files. To run static files compilation I'm using entrypoint in Compose file.

docker-compose.yml:

version: "3.9"

services:
  nginx:
    image: nginx
    healthcheck:
      test: curl --fail -s http://localhost:80/lib/tether/examples/viewport/index.html || exit 1
      interval: 1m
      timeout: 5s
      retries: 3
    volumes:
      - /www:/usr/share/nginx/html/
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - node.role == manager
    ports:
      - "8000:80"
    depends_on:
      - client

  client:
    image: my-client-image:latest
    restart: "no"
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - node.role == manager
    volumes:
      - /www:/app/www
    entrypoint: /entrypoint.sh

entrypoint.sh

./node_modules/.bin/gulp compilescss

I tried adding restart: "no" in my service, but service is restarted on entrypoint completion anyway

答案1

得分: 1

Docker 23.0.0 现已发布。因此,您有两个选项:

  • stack 文件现在支持 Swarm 任务。Swarm 了解这些任务会运行到完成,即 mode: replicated-job

  • Docker Compose V3 参考文档 明确指出 "restart:" 适用于 Compose,而 "deploy.restart_policy.condition: on-failure" 则是等效的 Swarm 语句。

英文:

Docker 23.0.0 is now out. As such you have two options:

  • stack files now support swarm jobs. Swarm understands that these run to completion. i.e. mode: replicated-job.

  • Docker Compose V3 Reference makes it clear that "restart:" applies to compose and "deploy.restart_policy.condition: on-failure" is the equivalent swarm statement.

huangapple
  • 本文由 发表于 2023年2月6日 21:39:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75362040.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定