Docker Learning Notes (6) Stacks

Keywords: Big Data Docker Redis

Stack is actually a set of interrelated services. Generally, all the services of an application are placed in one stack, and the deployment of an application can be accomplished in one click through the. yml file. Of course, more complex applications may be split into multiple stacks. In the preceding note. We deployed the stack of a single service, and the demo in this section deployed more services in this stack.

Note

In this article, demo refers to the official documentation of docker, and conditional friends suggest that you read the original Link directly: https://docs.docker.com/get-started/part5/#persist-the-data

Demo

Modify the hello-service.yml file to add two new services: visualizer and Redis.

  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
  redis:
    image: redis
    ports:
      - "6379:6379"
    volumes:
      - "/home/hunk/docker:/data"
    deploy:
      placement:
        constraints: [node.role == manager]
    command: redis-server --appendonly yes
    networks:
      - webnet

node.role == manager specifies that instances of this service run on the swarm manager node and are not assigned to the worker node

Deployment application

root@hunk-virtual-machine1:/home/hunk/docker# docker stack deploy -c hello-service.yml hello-service
Updating service hello-service_visualizer (id: pjb8l0antomhh6riulm3k3o7n)
Creating service hello-service_redis
Updating service hello-service_web (id: y46ique6nw7taei64dfm44c6s)
root@hunk-virtual-machine1:/home/hunk/docker# docker service ls
ID            NAME                      MODE        REPLICAS  IMAGE
633175oy620e  hello-service_redis       replicated  1/1       redis:latest
pjb8l0antomh  hello-service_visualizer  replicated  1/1       dockersamples/visualizer:stable
y46ique6nw7t  hello-service_web         replicated  5/5       hebostary/gohead:demo1
root@hunk-virtual-machine1:/home/hunk/docker# docker stack ls
NAME           SERVICES
hello-service  3

Visit hello-service_visualizer

Access hello-service_web

 

 

Posted by sujithfem on Thu, 31 Jan 2019 18:24:15 -0800