10

Is there a way to stop, start the single task in docker swarm mode, And how to do this?

JNI_OnLoad
  • 5,472
  • 4
  • 35
  • 60
sope
  • 1,619
  • 5
  • 19
  • 37

2 Answers2

9

Scale down to 0

e.g.

> docker service scale tpg6hs1c4atg=0
tpg6hs1c4atg scaled to 0
overall progress: 0 out of 0 tasks
verify: Service converged
Naor Bar
  • 1,991
  • 20
  • 17
5

At the moment the only way to run containers in swarm mode is to create a service: docker service create --name my-service my/image. Also, if you want to "stop" a service, you have to remove it: docker service rm my-service.

In future you'll be able to start services using DAB files, which are quite similar to docker-compose.yml files, but for docker swarm mode.

ronkot
  • 5,915
  • 4
  • 27
  • 41
  • But I have some requirement in my business to stop single task, and delete the shutdown status task. for example: high concurrency need more container will autoscale the service to increase the tasks and then reduce the tasks at normal time when access is not high. at this time will appear many shutdown status tasks which useless for business – sope Aug 15 '16 at 08:27
  • 3
    @sope Why don't you just scale down the Docker service? That will reduce the number of tasks. See: https://docs.docker.com/engine/swarm/swarm-tutorial/scale-service/ BTW autoscaling services is not supported by the docker engine yet. Presumably this is coming in a future version. If you need this feature now, considering using an alternative docker orchestration engine like Kubernetes. – Mark O'Connor Aug 15 '16 at 22:38
  • I know the autoscaling is not supported at the latest version of swarmkit. So I implement it in my code to call the remote api of docker engine. – sope Aug 16 '16 at 06:09
  • I wrote scaltainer to auto scale swarm services based on app metrics like average response time or job queue size https://github.com/hammady/scaltainer – hammady Dec 18 '17 at 18:45