Docker: Difference between `docker run` and `docker service`

The docker run command creates and starts a container on the local docker host.

A docker "service" is one or more containers with the same configuration running under docker's swarm mode. It's similar to docker run in that you spin up a container. The difference is that you now have orchestration. That orchestration restarts your container if it stops, finds the appropriate node to run the container on based on your constraints, scale your service up or down, allows you to use the mesh networking and a VIP to discover your service, and perform rolling updates to minimize the risk of an outage during a change to your running application.


Docker Run vs Docker service

docker run:

we can create number of containers with different images.

docker service:

we can create number of containers with same image in a single command line.

SYNTAX:

docker service create --name service-name --network network-name --replicas number-of-containers image-name

EXAMPLE:

docker service create --name service1 --network swarm-net --replicas 5 redis