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.
docker network create -d overlay backend
: This command creates an overlay network named "backend" which allows communication between services running on different Swarm nodes.docker network create -d overlay frontend
: This command creates another overlay network named "frontend" which serves as the external network for the application.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".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.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.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.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".