Build and deploy voting app using docker
👉 First will try to understand application If you look at the architecture here we have voting app based in Python and then Redis messaging system then the vote is cast and it goes to the worker (based on dot net) and vote is updated in postgress database and finally result is display in Node JS web application.
Redis and Postgres are the two component.
Voting app, result app and worker that we develop.
There are 3 folders in code repository and will look step by step
vote
If we click on the vote directory you will be able to see the source code of it and its a python based application so you have app.py with the python code in it.
If you open the python code it's a flask based application its very simple application.
It has a post and a get request the get request sends an index.html which shows the actual webpage where user can cast the vote.
And where user cast the vote it comes to this post section and that is where it establishes connectivity to redis and tries to store the vote information in redis.
Along with this we have docker file so it create from python image and then sets the working app.
worker
This is dot net based application at the top it tries to connect redis and postgress database and there is while loop when votes is cast it takes the vote and updates the table in the postgress database.
Also here we have docker file and it is based on Microsoft dotnet SDK and that where it has the source code of the application to the worker folder.
And finally updates the command required to start the worker.
result-app
It is based in node JS and open server.js and it is express based server and you can see the source code for that and all this does it establishes the connectivity to the postgress database and as you can see the postgress database that host to try to connect is db. and reach value of database and display in UI
And if you look at the docker file for that it starts from the docker image start from the Node JS slim image
How are we going to start deploying?
Clone the source code repository to local system.
git clone https://github.com/dockersamples/example-voting-app.git
Now will look for the docker file in vote folder
cd /example-voting-app/vote
So we will now go ahead and build the docker image by running the docker build command and will tag it with name voting-app.
docker build . -t voting-app
So docker image is built if you see running docker images command you will see.
Now we need to build redis container
docker run -d --name=redis redis
Now start the instance of voting app so run docker run command with voting app and publish port 5000
docker run -d -p 5000:80 --link redis:redis voting-app
we will proceed to the worker now to start that we need prerequisite of postgress database so will first deploy a postgress database instance.
docker run -d --name=db postgres:15-alpine
So now will go ahead and deploy the worker so will build the worker first.
docker build . -t worker-app
docker run -d --link redis:redis --link db:db worker-app
Next step is to build an deploy result app and publish to port 5001 will create image for result app and link it to postgress
docker build . -t result-app
docker run -d -p 5001:80 --link db:db result-app
So that is it you have deploy all the competencies application and you will see the list of images
docker images
Now you can see the container also.
docker ps
My votes goes for AWS
So every time I change my vote it goes through the full cycle and data goes to redis the worker processes it updates the database and then its finally shown in below result page
That's great, if you have make till here we understood how it works and we also successfully deployed it with docker run commands using links
If you liked what you read, do follow and any feedback for further improvement will be highly appreciated!
Thank you and Happy Learning!👏