Build and deploy voting app using docker

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.

💡
Tech:- We are using here just a Oracle Virtual box with CentOS installed operating system in it and not any other cloud provider.
  1. Redis and Postgres are the two component.

  2. Voting app, result app and worker that we develop.

There are 3 folders in code repository and will look step by step

  1. vote

    1. 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.

    2. If you open the python code it's a flask based application its very simple application.

    3. 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.

    4. 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.

    5. Along with this we have docker file so it create from python image and then sets the working app.

  2. worker

    1. 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.

    2. 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.

    3. And finally updates the command required to start the worker.

  3. result-app

    1. 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

    2. 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?
We will go and try and deploy this application ourselves with docker. But the first thing that we need to build this images, redis and postgress database have already images in docker.hub but for other three we need to built the images, So will start to clone the repository.

Clone the source code repository to local system.

git clone https://github.com/dockersamples/example-voting-app.git
  1. Now will look for the docker file in vote folder

     cd /example-voting-app/vote
    
  2. 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
    
  3. So docker image is built if you see running docker images command you will see.

  4. Now we need to build redis container

     docker run -d --name=redis redis
    
  5. 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
    
  6. 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
    
  7. 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
    
  8. 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
    
  9. So that is it you have deploy all the competencies application and you will see the list of images

     docker images
    

  10. Now you can see the container also.

    docker ps
    

  11. My votes goes for AWS

  12. 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!👏