0

I have some containers that need to be started as services in a swarm cluster. The point is that the container will run a service at a certain time and after that it must be removed.

How do I remove a service after the container runs what it needs and stops?

The --restart-condition flag already helps me to run only once, but I still need it to be removed to be created again the next time.

# docker --version
Docker version 19.03.13, build 4484c46d9d

Update:

To work around this, after docker services create I run:

while docker service ps --filter "desired-state=Running" ${DOCKER_SERVICE} | grep ${DOCKER_SERVICE} >/dev/null 2>&1 ; do sleep 1; done &&
   docker service rm ${DOCKER_SERVICE}

But I think this is not a best way

  • Your running into the x and y problem, IMHO, why not fix the original issue!? – djdomi May 22 '21 at 10:03
  • I don't think you understand the issue well. I don't have an "original issue". I need the service to be deleted as soon as the script that runs in the container ends and the container is in a Shutdown state. – Fausto Branco May 23 '21 at 17:25
  • As workaround after the docker service create ... I run thew shell: "while docker service ps --filter "desired-state=Running" ${DOCKER_SERVICE} | grep ${DOCKER_SERVICE} >/dev/null 2>&1 ; do sleep 1; done && docker service rm ${DOCKER_SERVICE}" But I think this is not a best way – Fausto Branco May 23 '21 at 17:26
  • is your service that needs to be deleted a secret? how's about to update your question to reflect what is going on for the reason you wanna trow the complete container away? – djdomi May 23 '21 at 20:34
  • I think you'd be better off with `--mode=replicated-job` rather than using the restart conditions. – BMitch May 23 '21 at 20:58

0 Answers0