Create Multi-Service App

Assignment

  • Using Docker's Distributed Voting App
  • use swarm-app-1 directory in our course repo for requirements
  • 1 volume, 2 networks, and 5 services needed
  • Create the commands needed, spin up services, and test app
  • Everything is using Docker Hub images, so no data needed on Swarm
  • Like many computer things, this is 1/2 art form and 1/2 sience

Goal: create networks, volumes, and services for a web-based "cats vs. dogs" voting app.

  • See architecture above for a basic diagram of how the 5 services will work
  • All images are on Docker Hub, so you should use editor to craft your commands locally, then paste them into swarm shell (at least that's how I'd do it)
  • a backend and frontend overlay network are needed. Nothing different about them other then that backend will help protect datatbase from the voting web app. (similar to how a VLAN setup might be in traditional archecture)
  • The database server should use a named volume for perserving data. Use the new --mount format to do this: --mount type=volume,source=db-data,target=/var/lib/postgresql/data
Services (names below should be service names)
  • vote

    • dockersamples/examplevotingapp_vote:before
    • web front end for users to vote dog/cat
    • ideally published on TCP 80. Container listens on 80
    • on frontend network
    • 2+ replicas of this container
  • redis

    • redis:3.2
    • key/value storage for incoming votes
    • no public ports
    • on frontend network
    • 2 replicas
  • worker

    • dockersamples/examplevotingapp_worker
    • backend processor of redis and storing results in postgres
    • no public ports
    • on frontend and backend networks
    • 1 replica
  • db

    • postgres:9.4
    • one named volume needed, pointing to /var/lib/postgresql/data
    • on backend network
    • 1 replica
  • result

    • dockersamples/examplevotingapp_result:before
    • web app that shows results
    • runs on high port since just for admins (lets imagine)
    • so run on a high port of your choosing (I choose 5001), container listens on 80
    • on backend network
    • 1 replica

Solution

  • I have 3 nodes up and running (Doesn't really matter if locally or on some service)
  • Swarm is enabled and machines are connected.
    • All three are manager nodes at the start.
~> docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
jrc8bx32n4oqbseh5dm2acim3 *   node1               Ready               Active              Leader
53v7pxgv16ymbell5ov0ey3a9     node2               Ready               Active              Reachable
mezwronjtc6p1fz0cf6e65iuo     node3               Ready               Active              Reachable

~> docker node ps
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE   ERROR               PORTS

~> docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
  • Create network (we need to use overlay driver)
~> docker network create -d overlay backend
i0ikqbla1dswpxez8rspyrftg
~> docker network create -d overlay frontend
a9h3gtdrpkrc2ij6digs8l2g7
  • Services to deploy
# vote
docker service create --name vote -p 80:80 --network frontend --replicas 2 dockersamples/examplevotingapp_vote:before

#redis
docker service create --name redis --network frontend redis:3.2

# worker
docker service create --name worker --network frontend --network backend dockersamples/examplevotingapp_worker

# db
docker service create --name db --mount type=volume,source=db-data,target=/var/lib/postgresql/data --network backend postgres:9.4

# result
docker service create --name result -p 5001:80 --network backend dockersamples/examplevotingapp_result:before



~> docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                                          PORTS
q2v4t6h5w752        db                  replicated          1/1                 postgres:9.4                         
mw576s90xykf        redis               replicated          1/1                 redis:3.2                            
nkb8zf4jqc0j        result              replicated          1/1                 dockersamples/examplevotingapp_result:before   *:5001->80/tcp
elysocd93pro        vote                replicated          2/2                 dockersamples/examplevotingapp_vote:before     *:80->80/tcp
7vovb3mxvtde        worker              replicated          1/1                 dockersamples/examplevotingapp_worker:latest

Everything is running as it should.

  • Our voting application:

  • And our results application on port 5001

results matching ""

    No results matching ""