Introduction

After learning about Swarm and Docker, I embarked on creating a multi-service multi-node app. I progressed further on my journey to my next project, I used skills I have gained so far to write a series of commands to set up the required services and networks. Below is a brief explanation of each command along with the architecture diagram.

My Docker Multi-Service Multi-Node App Architecture

architecture.png

Command Explanation:

  1. docker network create -d overlay backend: This command creates an overlay network named "backend" which allows communication between services running on different Swarm nodes.
  2. docker network create -d overlay frontend: This command creates another overlay network named "frontend" which serves as the external network for the application.
  3. docker service create --name vote -p 80:80 --network frontend --replicas 2 bretfisher/examplevotingapp_vote: This command creates a service named "vote" with 2 replicas, using the "frontend" network. It maps port 80 on the host to port 80 on the container. The image used is "bretfisher/examplevotingapp_vote".
  4. docker service create --name redis --network frontend redis:3.2: This command creates a service named "redis" using the "frontend" network. It uses the Redis 3.2 image.
  5. docker service create --name db --network backend -e POSTGRES_HOST_AUTH_METHOD=trust --mount type=volume,source=db-data,target=/var/lib/postgresql/data postgres:9.4: This command creates a service named "db" using the "backend" network. It sets the environment variable POSTGRES_HOST_AUTH_METHOD to "trust" for easier development. It also mounts a volume for persistent storage.
  6. docker service create --name worker --network frontend --network backend bretfisher/examplevotingapp_worker: This command creates a service named "worker" using both the "frontend" and "backend" networks. It uses the "bretfisher/examplevotingapp_worker" image.
  7. docker service create --name result --network backend -p 5001:80 bretfisher/examplevotingapp_result: This command creates a service named "result" using the "backend" network. It maps port 5001 on the host to port 80 on the container. The image used is "bretfisher/examplevotingapp_result".

Working

Screenshot 2023-12-28 162917.png

Screenshot 2023-12-28 162935.png

Screenshot 2023-12-28 162943.png

Screenshot 2023-12-28 160908.png