How To Create And Manage Docker Service
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed docker swarm.
https://cloudaffaire.com/how-to-create-and-manage-docker-swarm-cluster/
In this blog post, we will discuss docker service. We will also deploy a docker service in our existing docker swarm cluster.
Prerequisite for this demo:
- Docker swarm cluster initiated and configured
What is docker service?
In a distributed application, different pieces of the app are called “services”. For example, if you imagine a video sharing site, it probably includes a service for storing application data in a database, a service for video transcoding in the background after a user uploads something, a service for the front-end, and so on.
Services are really just “containers in production.” A service only runs one image, but it codifies the way that image runs—what ports it should use, how many replicas of the container should run so the service has the capacity it needs, and so on. Scaling a service changes the number of container instances running that piece of software, assigning more computing resources to the service in the process.
How To Create And Manage Docker Service Demo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
##------------------------ ## Docker: Docker Services ##------------------------ ## docker service COMMAND ########################### ## Swarm Configuration ## ########################### # hostnames ip os role # --------- ------------ -------- ------------ # system1 192.168.0.10 Centos 7 Manager Node # system2 192.168.0.20 Centos 7 Worker Node One # system3 192.168.0.30 Centos 7 Worker Node Two ############################### ## Deploy a docker service ## ############################### ## Login to docker swarm manager node (192.168.0.10) ## Create a network docker network create -d overlay myhttpdnet ## Create a new service docker service create --name myhttpdservice --replicas 2 --publish 8080:80/tcp --network myhttpdnet httpd ################################# ## Docker service management ## ################################# ## List services docker service ls ## Display detailed information on one or more services docker service inspect myhttpdservice ## Fetch the logs of a service or task docker service logs myhttpdservice ## List the tasks of one or more services docker service ps myhttpdservice ## Scale one or multiple replicated services docker service scale myhttpdservice=3 ## Update a service docker service update --publish-add 8000:80/tcp myhttpdservice ## Revert changes to a service"s configuration docker service rollback myhttpdservice ## Remove one or more services docker service rm myhttpdservice |
Hope you have enjoyed this article. In the next blog post, we will discuss docker stack.
To get more details on docker, please refer below docker documentation