Las bondades que nos proporciona docker-compose se pueden aplicar al swarm. Esto es, la configuración de los servicios por medio de archivos de configuración. Utilizaremos el ejemplo del lab anterior donde tenemos un swarm con un vizualizador y un web simple nginx.
el archivo viz.yml
version: "3.1" services: viz: image: dockersamples/visualizer ports: - 8080:8080 volumes: - /var/run/docker.sock:/var/run/docker.sock deploy: placement: constraints: [node.role == manager ]
el archivo web.yml
version: "3.1" services: web1: image: nginx ports: - 8081:80 web2: image: httpd ports: - 8082:80 web3: image: httpd ports: - 8083:80
Ahora vamos a terminar los servicios viz y web. primero antes de deployarlos en el nuevo stack.
bext@bext-VPCF13WFX:~$ docker stack deploy -c viz.yml viz Creating network viz_default Creating service viz_viz failed to create service viz_viz: Error response from daemon: rpc error: code = InvalidArgument desc = port '8080' is already in use by service 'viz' (1k6akx8sh6yrod7zsi5cvf71a) as an ingress port bext@bext-VPCF13WFX:~$ docker service ls ID NAME MODE REPLICAS IMAGE PORTS 1k6akx8sh6yr viz replicated 1/1 dockersamples/visualizer:latest *:8080->8080/tcp vtuogblw02ak web replicated 2/2 nginx:latest *:80->80/tcp bext@bext-VPCF13WFX:~$ docker service rm viz viz bext@bext-VPCF13WFX:~$ docker service ls ID NAME MODE REPLICAS IMAGE PORTS vtuogblw02ak web replicated 2/2 nginx:latest *:80->80/tcp bext@bext-VPCF13WFX:~$ docker stack deploy -c viz.yml viz Creating service viz_viz bext@bext-VPCF13WFX:~$ nano web.yml bext@bext-VPCF13WFX:~$ docker service rm web web bext@bext-VPCF13WFX:~$ docker stack deploy -c web.yml web Creating network web_default Creating service web_web2 Creating service web_web3 Creating service web_web1 bext@bext-VPCF13WFX:~$ docker service ls ID NAME MODE REPLICAS IMAGE PORTS uu15oc0t9mc6 viz_viz replicated 1/1 dockersamples/visualizer:latest *:8080->8080/tcp aszigymy7adn web_web1 replicated 1/1 nginx:latest *:8081->80/tcp pqb4wultub03 web_web2 replicated 1/1 httpd:latest *:8082->80/tcp qpx5b2wyge0d web_web3 replicated 1/1 httpd:latest *:8083->80/tcp
bext@bext-VPCF13WFX:~$ docker stack ps web ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS y61pa7cwj5oa web_web1.1 nginx:latest sw-master Running Running 40 seconds ago wd0fh80ckwpj web_web3.1 httpd:latest sw-worker-2 Running Running 22 seconds ago zr1uwvrbdw6p web_web2.1 httpd:latest sw-worker-1 Running Running 21 seconds ago
Modificamos el web.yml para redeployarlo.
webv2.yml
version: "3.1" services: web1: image: nginx ports: - 8081:80 deploy: replicas: 3 web2: image: httpd ports: - 8082:80 deploy: replicas: 2
bext@bext-VPCF13WFX:~$ docker stack deploy -c webv2.yml web Updating service web_web1 (id: aszigymy7adnix8q5lrhj9v1y) Updating service web_web2 (id: pqb4wultub03vakv0ym2z41c7) bext@bext-VPCF13WFX:~$ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 171572f3eff1 nginx:latest "nginx -g 'daemon of…" 9 minutes ago Up 9 minutes 80/tcp web_web1.1.y61pa7cwj5oai3cocmhf686vb 3e340e21423e dockersamples/visualizer:latest "npm start" 14 minutes ago Up 14 minutes (healthy) 8080/tcp viz_viz.1.zq62g7exoqfpgj8efqy4h76cd bext@bext-VPCF13WFX:~$ docker service ls ID NAME MODE REPLICAS IMAGE PORTS uu15oc0t9mc6 viz_viz replicated 1/1 dockersamples/visualizer:latest *:8080->8080/tcp aszigymy7adn web_web1 replicated 3/3 nginx:latest *:8081->80/tcp pqb4wultub03 web_web2 replicated 2/2 httpd:latest *:8082->80/tcp qpx5b2wyge0d web_web3 replicated 1/1 httpd:latest *:8083->80/tcp bext@bext-VPCF13WFX:~$ docker service rm web_web_3 Error: No such service: web_web_3 bext@bext-VPCF13WFX:~$ docker service rm qpx5b2wyge0d qpx5b2wyge0d bext@bext-VPCF13WFX:~$ docker service ls ID NAME MODE REPLICAS IMAGE PORTS uu15oc0t9mc6 viz_viz replicated 1/1 dockersamples/visualizer:latest *:8080->8080/tcp aszigymy7adn web_web1 replicated 3/3 nginx:latest *:8081->80/tcp pqb4wultub03 web_web2 replicated 2/2 httpd:latest *:8082->80/tcp
eot.
well! Thanks for providing the information
ResponderEliminarDocker and Kubernetes Training
Docker and Kubernetes Online Training
Docker and Kubernetes Training in Hyderabad