Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Docker Service and Docker Container?

When do we use a docker service create command and when do we use a docker run command?

like image 617
Kunal Sehegal Avatar asked Apr 14 '17 09:04

Kunal Sehegal


People also ask

What is difference between service and container?

Services and container are related but both are different things. A service can be run by one or multiple containers. With docker you can handle containers and with docker-compose you can handle services. This compose file defines two services, web and db .

What is the Docker service?

Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime.

Which container does Docker service use?

docker service create is used to create instances (called tasks) of that service running in a cluster (called swarm) of computers (called nodes). Those tasks are containers of cource, but not standalone containers. In a sense a service acts as a template when instantiating tasks.

What is the difference between Docker service and Kubernetes service?

In a nutshell, Docker is a suite of software development tools for creating, sharing and running individual containers; Kubernetes is a system for operating containerized applications at scale. Think of containers as standardized packaging for microservices with all the needed application code and dependencies inside.


2 Answers

In short: Docker service is used mostly when you configured the master node with Docker swarm so that docker containers will run in a distributed environment and it can be easily managed.

Docker run: The docker run command first creates a writeable container layer over the specified image, and then starts it using the specified command.

That is, docker run is equivalent to the API /containers/create then /containers/(id)/start

source: https://docs.docker.com/engine/reference/commandline/run/#parent-command

Docker service: Docker service will be the image for a microservice within the context of some larger application. Examples of services might include an HTTP server, a database, or any other type of executable program that you wish to run in a distributed environment.

When you create a service, you specify which container image to use and which commands to execute inside running containers. You also define options for the service including:

  • the port where the swarm will make the service available outside the swarm
  • an overlay network for the service to connect to other services in the swarm
  • CPU and memory limits and reservations
  • a rolling update policy
  • the number of replicas of the image to run in the swarm

source: https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/#services-tasks-and-containers

like image 182
Viswesn Avatar answered Sep 23 '22 15:09

Viswesn


  • docker run is used to create a standalone container
  • docker service create is used to create instances (called tasks) of that service running in a cluster (called swarm) of computers (called nodes). Those tasks are containers of cource, but not standalone containers. In a sense a service acts as a template when instantiating tasks.

For example

docker service create --name MY_SERVICE_NAME --replicas 3 IMAGE:TAG 

creates 3 tasks of the MY_SERVICE_NAME service, which is based on the IMAGE:TAG image.

More information can be found here

like image 37
Teo Bebekis Avatar answered Sep 21 '22 15:09

Teo Bebekis