英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论