Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 248
CuriousMind Avatar asked Oct 09 '17 12:10

CuriousMind


People also ask

What is the difference between docker service and docker container?

Docker Container is a runtime instance of Docker Image. Docker Service can run one type of Docker Images on various containers locating on different nodes to perform the same functionality.

What is a 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.

What is the difference between docker run and docker start?

Docker start command will start any stopped container. If you used docker create command to create a container, you can start it with this command. Docker run command is a combination of create and start as it creates a new container and starts it immediately.

Can docker run as a service?

Run Docker Container as a Service Docker team recommends to use cross-platform built-in restart policy for running container as a service. For this, configure your docker service to start on system boot and simply add parameter --restart unless-stopped to the docker run command that starts YouTrack.


2 Answers

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.

like image 63
BMitch Avatar answered Oct 22 '22 08:10

BMitch


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
like image 44
lakshmi jodi Avatar answered Oct 22 '22 06:10

lakshmi jodi