54

I am wondering what the difference between such things. They have got almost the same commands and give the same result.

prisar
  • 3,041
  • 2
  • 26
  • 27
Dmytro Nalyvaiko
  • 1,664
  • 4
  • 16
  • 27

3 Answers3

79

The docker service is used when managing individual service on a docker swarm cluster. It is the client command line to access the docker swarm manager.

The docker stack can be used to manage a multi-service application. It also moves many of the options you would enter on the docker service into the .yml file (such as docker-cloud.yml or docker-compose.yml) for easier reuse. It works as a front end "script" on top of the docker swarm manager used by docker swarm cluster, so you can do everything docker stack does with docker service.

Last but not least, you can consider the docker service vs docker stack is the same as docker run vs docker compose, but in the docker swarm cluster.

benjah1
  • 1,440
  • 1
  • 13
  • 17
46

A Service defines one or more instances of a single image deployed on one or more machines (described by one entry in the services part of the docker-compose.yaml files).

A Stack defines a group of heterogeneous services (described by the whole yaml file).

demented hedgehog
  • 7,007
  • 4
  • 42
  • 49
  • 9
    Thank you. The accepted answer is an example of why Docker is so hard to understand. – Florimond May 06 '18 at 17:22
  • Contrary to the feedback here, I feel like this answer is a tiny bit misleading. My understanding is that a service is only a *single instance* of an image, as [described by the Docker documentation](https://docs.docker.com/v17.12/engine/swarm/key-concepts/#services-and-tasks). This answer states that a service is "one or more instances", which I believe is incorrect. Perhaps the author can clarify what was meant by this statement, or edit to remove this assertion all together. – void.pointer Apr 10 '19 at 15:01
  • 2
    @void.pointer From the documentation you link to.. "A service is the definition of the tasks to execute on the manager or worker nodes." note the plural for tasks in that line. See here https://docs.docker.com/v17.12/get-started/part3/#docker-composeyml and you will see how a service is defined. Check out the replicas setting. So each service when it starts will start multiple tasks which are instances of an image. – demented hedgehog Apr 11 '19 at 21:23
  • But they call them tasks not services. I stand by my claim that this answer is confusing. At the very least because the terminology is not consistent with the documentation. – void.pointer Apr 13 '19 at 00:29
  • 2
    @void.pointer Changed "A Service is one or more instances of a single image" to "A Service defines one or more instances of a single image" – demented hedgehog Apr 13 '19 at 02:45
0

The semantics of docker stack deploy can simplify your release automation process because it will automatically detect and update an existing service. When using docker service you must specify whether to create or update the service which could require more complex logic.

See also:

user700390
  • 2,287
  • 1
  • 19
  • 26