What is the difference between docker service and stack?

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


Solution 1:

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.

Solution 2:

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