## 11.2.5 Creating a Docker service 

In this step, we defined a cluster service called web server . This service provides the nginx application. Example 8 shows the service status before the command is run. Then, we deploy a new service and check the status to confirm that web server service was created. 

These commands must run in any manager node that is part of the cluster. In our example, we ran it in the sc74cn09.pbm.ihost.com  server. 

admin@01f543067055:~$ docker service ls ID NAME MODE REPLICAS IMAGE PORTS admin@01f543067055:~$ docker service create --name webserver -p 80:80 nginx:latest pwu25hj3wpwwovo73d2is31gn overall progress: 1 out of 1 tasks 1/1: running [==================================================>] verify: Service converged admin@01f543067055:~$ docker service ls ID NAME MODE REPLICAS IMAGE PORTS pwu25hj3wpww webserver replicated 1/1 nginx:latest *:80->80/tcp 

You can get more information about the web server service by running the command that is shown in Example 11-9 (the nginx container was started in sc74cn04.pbm.ihost.com server, which is the worker node. Remember that we removed sc74cn03.pbm.ihost.com and sc74cn09.pbm.ihost.com  from receiving application workloads because they were drained in a previous step. By default, only one replica is started. 

admin@01f543067055:~$ docker service ps webserver ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORT vkqgrr6aypi3 webserver.1 nginx:latest sc74cn04.pbm.ihost.com Running Running 2 minutes ago 

Now, we stopped the container on sc74cn04.pbm.ihost.com  server to see the behavior when someone takes down a container that is managed by swarm (see Example 11-10). 

admin@a29d70c73c55:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAME 0f0fac618197 nginx:latest "nginx -g 'daemon of…" 5 minutes ago Up 5 minutes 80/tcp webserver.1.vkqgrr6aypi3e8ue88wuqedxw a29d70c73c55 ibm_zcx_zos_cli_image "sudo /usr/sbin/sshd…" 2 hours ago Up 2 hours 8022/tcp, 0.0.0.0:8022->22/tcp ibm_zcx_zos_cli admin@a29d70c73c55:~$ docker stop 0f0fac618197 0f0fac618197 admin@a29d70c73c55:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAME e5a065c3177b nginx:latest "nginx -g 'daemon of…" 6 seconds ago Up Less than a second 80/tcp webserver.1.2y909gfnju13ybtxwsknljuyr a29d70c73c55 ibm_zcx_zos_cli_image "sudo /usr/sbin/sshd…" 2 hours ago Up 2 hours 8022/tcp, 0.0.0.0:8022->22/tcp ibm_zcx_zos_cli 

