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

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

Docker Swarm - don't restart service on entrypoint success

问题

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

docker-compose.yml:

  1. version: "3.9"
  2. services:
  3. nginx:
  4. image: nginx
  5. healthcheck:
  6. test: curl --fail -s http://localhost:80/lib/tether/examples/viewport/index.html || exit 1
  7. interval: 1m
  8. timeout: 5s
  9. retries: 3
  10. volumes:
  11. - /www:/usr/share/nginx/html/
  12. deploy:
  13. mode: replicated
  14. replicas: 1
  15. placement:
  16. constraints:
  17. - node.role == manager
  18. ports:
  19. - "8000:80"
  20. depends_on:
  21. - client
  22. client:
  23. image: my-client-image:latest
  24. restart: "no"
  25. deploy:
  26. mode: replicated
  27. replicas: 1
  28. placement:
  29. constraints:
  30. - node.role == manager
  31. volumes:
  32. - /www:/app/www
  33. entrypoint: /entrypoint.sh

entrypoint.sh:

  1. ./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:

  1. version: "3.9"
  2. services:
  3. nginx:
  4. image: nginx
  5. healthcheck:
  6. test: curl --fail -s http://localhost:80/lib/tether/examples/viewport/index.html || exit 1
  7. interval: 1m
  8. timeout: 5s
  9. retries: 3
  10. volumes:
  11. - /www:/usr/share/nginx/html/
  12. deploy:
  13. mode: replicated
  14. replicas: 1
  15. placement:
  16. constraints:
  17. - node.role == manager
  18. ports:
  19. - "8000:80"
  20. depends_on:
  21. - client
  22. client:
  23. image: my-client-image:latest
  24. restart: "no"
  25. deploy:
  26. mode: replicated
  27. replicas: 1
  28. placement:
  29. constraints:
  30. - node.role == manager
  31. volumes:
  32. - /www:/app/www
  33. entrypoint: /entrypoint.sh

entrypoint.sh

  1. ./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:

确定