martes, 2 de julio de 2019

Docker Stack Part5 Lab Python Flask Redis



https://github.com/jalbertomr/DockerSampleApp/commit/cededc9266db3f99a7b7eb2229d6e8a4f490fa7e

   Ahora finalmente haremos el enlace de la aplicación web con el redis, habilitando el contador. Esto se hará configurando un archivo docker-compose.yml que describe los servicios y características de los mismos que se ejecutarán en el stack. los containers dentro del stack pueden comunicarse los unos a los otros al estar en una misma red. así tendremos en el mismo stack el redis y web. cabe notar que le debemos especificar el directorio de trabajo al redis, o sea un volumen.

- Levantamos las tres máquinas virtuales.
- Verificamos el estado del swarm en las máquinas virtuales con comandos comunes.
- integramos la linea de comandos de la vm master a la máquina host, para no estar escribiendo docker-machine ssh vm "comandos..."

docker-composev3.yml
version: "3"services:
  web:
    #remplazar username/repo:tag con el nombre y imagen    #image: username/repo:tag    image: jalbertomr/lab1:miapp80
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "80:80"    networks:
      - webnet
  visualizer:
    image: dockersamples/visualizer:stable
    ports:
      - "8080:8080"    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"    deploy:
      placement:
        constraints: [node.role == manager]
    networks:
      - webnet
  portainer:
    image: portainer/portainer
    ports:
      - "9000:9000"    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"    deploy:
      placement:
        constraints: [node.role == manager]
    networks:
      - webnet
  redis:
    image: redis
    ports:
      - "6379:6379"    volumes:
      - "/home/docker/data:/data"    deploy:
      placement:
        constraints: [node.role == manager]
    command: redis-server --appendonly yes
    networks:
      - webnet
networks:
  webnet:


bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
kdaljefl1ech729w83jrdmqr9 *   bext-VPCF13WFX      Ready               Active              Leader              18.09.6

bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker-machine ssh sw-master "docker node ls"
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
pdlp62hc1wqzo5wuubp5ailmx *   sw-master           Ready               Active              Leader              18.09.7
qfc9sx1tfe3wms1oera75f80b     sw-worker-1         Ready               Active                                  18.09.7
v28filrne0x5fua7r7rxh6zew     sw-worker-2         Ready               Active                                  18.09.7

bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ eval $(docker-machine env sw-master)
bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
pdlp62hc1wqzo5wuubp5ailmx *   sw-master           Ready               Active              Leader              18.09.7
qfc9sx1tfe3wms1oera75f80b     sw-worker-1         Ready               Active                                  18.09.7
v28filrne0x5fua7r7rxh6zew     sw-worker-2         Ready               Active                                  18.09.7
bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker container ls
CONTAINER ID        IMAGE                             COMMAND             CREATED             STATUS              PORTS               NAMES
aa470dcbd277        portainer/portainer:latest        "/portainer"        2 minutes ago       Up 2 minutes        9000/tcp            miapp80lab_portainer.1.xm88pptnl8195i1mnxbbza9hn
a66ad99c3c31        dockersamples/visualizer:stable   "npm start"         12 minutes ago      Up 12 minutes       8080/tcp            miapp80lab_visualizer.1.yymvzcddts6200njgk2p0wisa
605543af5211        jalbertomr/lab1:miapp80           "python app.py"     12 minutes ago      Up 12 minutes       80/tcp              miapp80lab_web.3.x7o48c0bzadt7pldzip6l574c
7e747892e369        jalbertomr/lab1:miapp80           "python app.py"     12 minutes ago      Up 12 minutes       80/tcp              miapp80lab_web.5.fni0oi576q33y4od1mh0ou8mp
bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker services ls
docker: 'services' is not a docker command.
See 'docker --help'
bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker service ls
ID                  NAME                    MODE                REPLICAS            IMAGE                             PORTS
olbmomly7iae        miapp80lab_portainer    replicated          1/1                 portainer/portainer:latest        *:9000->9000/tcp
362njjjcdbpb        miapp80lab_redis        replicated          0/1                 redis:latest                      *:6379->6379/tcp
817s3pre274t        miapp80lab_visualizer   replicated          1/1                 dockersamples/visualizer:stable   *:8080->8080/tcp
cxlzjtcdhulm        miapp80lab_web          replicated          5/5                 jalbertomr/lab1:miapp80           *:80->80/tcp


bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ eval $(docker-machine env sw-master)
bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
pdlp62hc1wqzo5wuubp5ailmx *   sw-master           Ready               Active              Leader              18.09.7
qfc9sx1tfe3wms1oera75f80b     sw-worker-1         Ready               Active                                  18.09.7
v28filrne0x5fua7r7rxh6zew     sw-worker-2         Ready               Active                                  18.09.7
bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker container ls
CONTAINER ID        IMAGE                             COMMAND             CREATED             STATUS              PORTS               NAMES
aa470dcbd277        portainer/portainer:latest        "/portainer"        2 minutes ago       Up 2 minutes        9000/tcp            miapp80lab_portainer.1.xm88pptnl8195i1mnxbbza9hn
a66ad99c3c31        dockersamples/visualizer:stable   "npm start"         12 minutes ago      Up 12 minutes       8080/tcp            miapp80lab_visualizer.1.yymvzcddts6200njgk2p0wisa
605543af5211        jalbertomr/lab1:miapp80           "python app.py"     12 minutes ago      Up 12 minutes       80/tcp              miapp80lab_web.3.x7o48c0bzadt7pldzip6l574c
7e747892e369        jalbertomr/lab1:miapp80           "python app.py"     12 minutes ago      Up 12 minutes       80/tcp              miapp80lab_web.5.fni0oi576q33y4od1mh0ou8mp
 
bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker service ls
ID                  NAME                    MODE                REPLICAS            IMAGE                             PORTS
olbmomly7iae        miapp80lab_portainer    replicated          1/1                 portainer/portainer:latest        *:9000->9000/tcp
362njjjcdbpb        miapp80lab_redis        replicated          0/1                 redis:latest                      *:6379->6379/tcp
817s3pre274t        miapp80lab_visualizer   replicated          1/1                 dockersamples/visualizer:stable   *:8080->8080/tcp
cxlzjtcdhulm        miapp80lab_web          replicated          5/5                 jalbertomr/lab1:miapp80           *:80->80/tcp

El redis no esta disponible, le agregaremos a la vm donde se ejecuta el subdirectorio para su volumen.

bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker-machine ssh sw-master "mkdir ./data"

Redeployamos el stack
bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker stack deploy -c docker-composev3.yml miapp80lab
Updating service miapp80lab_visualizer (id: 817s3pre274thsvx0xumglmrt)
Updating service miapp80lab_portainer (id: olbmomly7iaejaaxmtg33ejg1)
Updating service miapp80lab_redis (id: 362njjjcdbpbnpw0gzn3dnpis)
Updating service miapp80lab_web (id: cxlzjtcdhulm1eftjvg6etul4) 
  
Verificamos la ejecución
bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
pdlp62hc1wqzo5wuubp5ailmx *   sw-master           Ready               Active              Leader              18.09.7
qfc9sx1tfe3wms1oera75f80b     sw-worker-1         Ready               Active                                  18.09.7
v28filrne0x5fua7r7rxh6zew     sw-worker-2         Ready               Active                                  18.09.7
bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker service ls
ID                  NAME                    MODE                REPLICAS            IMAGE                             PORTS
olbmomly7iae        miapp80lab_portainer    replicated          1/1                 portainer/portainer:latest        *:9000->9000/tcp
362njjjcdbpb        miapp80lab_redis        replicated          1/1                 redis:latest                      *:6379->6379/tcp
817s3pre274t        miapp80lab_visualizer   replicated          1/1                 dockersamples/visualizer:stable   *:8080->8080/tcp
cxlzjtcdhulm        miapp80lab_web          replicated          5/5                 jalbertomr/lab1:miapp80           *:80->80/tcp

 Ya vemos que esta ejecutandose el redis, lo verificamos en la página web si el contador funciona.


Vamos a hechar un vistaso al stack con portainer, para ejecutar portanier bajamos el servico visualizer para que no tenga conflicto con portainer.













eot

No hay comentarios:

Publicar un comentario