Search code examples
docker-composedocker-swarm

Docker Swarm - don't restart service on entrypoint success


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


Solution

  • 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.