I’d like to have a service deployed in Swarm run some commands then stop.
My compose file will start a service, run some commands, then run the commands again. As in an endless loop.
I added the following restart policy: restart: on-failure. When I deployed, I got the following message: Ignoring unsupported options: restart. However, the service ran the commands once.
My compose file is (showing relevant parts):
init-env:
image: ...
restart: on-failure
depends_on:
- ...
entrypoint: ['/bin/sh','-c']
command: |
"
# A bunch of commands are being executed in this section
...
"
networks:
- my_network
deploy:
replicas: 1
placement:
constraints: [node.labels.server == 1]
What’s the best way to implement my desired scenario? Is the ignore message a false positive?
If you use Swarm, you don’t need Docker compose so the version is irrelevant. Still thank you for sharing the versions without us asking for it.
I don’t know why it was restarted only once, but as the documentation says
Restart policies only apply to containers. Restart policies for swarm services are configured differently. See the flags related to service restart.
I also searched for the error message: Ignoring unsupported options: restart
and the first result was this:
which refers to this part of the documentation:
That shows Compose file v3 reference where there were restart: and deploy.restart_policy options as well. Using the new compose file specification and Compose v2 you could use the same for Docker Compose and Swarm