28

I am very new to docker , just started venturing into this. I read online about this. I came to know of the following commands of docker which is: docker run and docker service. As I understood , with docker run we are spinning a new container. However I am not clear what docker service do? Does it spin container in a Swarm?

Can anyone help understand in simple to understand?

CuriousMind
  • 8,301
  • 22
  • 65
  • 134

2 Answers2

55

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.

BMitch
  • 231,797
  • 42
  • 475
  • 450
11

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
J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
lakshmi jodi
  • 111
  • 1
  • 2