[Intro music]
Hello and welcome to this demo.
In this demo, we're going to look at the example-voting-app.
The example-voting-app is available in GitHub under the dockersamples
repository, and it is available at example-voting-app.
I will add a link to this in the resources section.
In this demo, we're going to look at the architecture of
this. We're going to look at the source code a little bit,
understand how it's put together, and we will try and deploy
this application using Docker.
But to start with, we're just going to deposit the application
with docker run just to make it really simple.
And then in the next demo, we'll try to use Docker Compose,
and going forward, we'll use Docker stack and services to
deploy it on Swarm.
So as a first step, let's try and just understand the application.
So the source code is available on GitHub, and you can see
basic documentation here.
If you look at the architecture, as we discussed in the lecture,
you have a voting-app which is based in Python, and then
you have a redis messaging system.
The vote is cast, and it goes to the worker, which is based
on .NET, and then the vote is updated in a Postgres database,
and then finally, the result is displayed in a Node.js based
result web application.
Out of these two of the components are Redis and Postgres,
so we don't have to worry about that.
The three other components are the applications that we developed.
So there are three folders in this code repository.
[No audio]
We'll first look at the voting-app, so if you click on the
vote directory, you will be able to see the source code of
it. And it's a Python based application.
So you have the app.py with the Python code in it.
If you open the Python code, it's a flask based application.
It's a very simple application.
It has a post and a get request.
The GET request sent an index.html which shows the actual
web page where a user can cast a vote.
And when the user cast a 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.
So that's all that this particular voting-application is.
And one thing to take note here is the host that it tries
to, it tries to connect to a host named redis.
Okay, now, alongside the code, we also have the Dockerfile,
so it creates it from a python :2.7-alpine image and then
set the working directory to app, installs the Python requirements.
[No audio]
The next step is where it copies the application code into
the app folder, and finally the Entrypoint for the application.
Next, we will take a look at the worker.
So go to the worker folder, and the source code of the application
is under the main/java/worker folder, and there is a Worker.java.
If you look at this code, this is .NET based application.
So at the top it tries to connect to the Redis and the Postgres
database. And there's a while loop where it waits for the
votes from redis.
And whenever a vote is cast and it's available in redis,
it takes that vote and updates the table in the Postgres
database. If you're interested, go through and take a look
at the remainder of the code.
We will then look at the Dockerfile.
So the Dockerfile is based on Microsoft dotnet SDK, and that
is where it adds the source code of the application to the
worker folder and finally updates the command required to
start the worker.
Next, we will look at the result-app, which is based in Node.js.
So that is under the result folder and open the server.js.
This is an express based server, and you can see the source code for that.
And all this does is it establishes a connectivity to the
Postgres database.
And as you can see, the Postgres database, that host that
tries to connect to is db. So that's the host name that it tries
to connect to, and then it reads the database and reads the
values from the database and displays that on the UI.
[No audio]
And if you look at the Dockerfile for that, it starts from
the Docker image, starts from a Node.js slim image, and then
adds the package.json, which has the dependencies, runs npm
install to install those dependencies, copies the source code
over, and finally specifies the node server.js command that
is to be run when the application starts.
And then there are also, in the source code repository
there are also some docker-compose and docker-stack files.
But we will not look at that right now.
We will be creating those ourselves.
So we will just ignore that.
So what we're going to do now is we'll just go try and deploy
this application ourselves with Docker.
But the first thing that we need to do is build these images,
because we know that the Redis and Postgres databases already
have images available on the Docker Hub, but the three others
are the applications that we are developing.
So we do not have images built for those, so we'll have to build them.
So I'm going to first clone the source code repository
to my local system.
So I will do a git clone and then paste the address, and
that will clone the source.
It is cloned it into example-voting-app.
And when I go into example-voting-app, I have all the code
that we just walked through.
Okay, so we will start with deploying the voting-app.
For that, we need to create a Docker image for the voting-app.
[No audio]
So we will go into the vote directory and we look at
the Dockerfile. The Dockerfile looks intact.
So we're just going to go ahead and build the Docker image
by running the docker build command, and we will tag it with
a name voting-app.
Okay, so the Docker image is built.
If you run the docker images command, you can see that it
has the voting-app image built.
So now that I have the voting-app image built, I can run
a Container by running the docker run voting-app command,
and I'm going to publish a Port 5000 to 80.
So the, the Container,
the voting-app Container runs on Port 80, and I'm going to
map that to Port 5000 on my host so that I can access it from a browser.
So it looks like the Container is running.
So I'm going to try and open a browser and go to the address
with Port 5000, and I can see that the web application is
displayed, and I can see two options to cast my vote, CATS and DOGS.
Now, if I try to cast a vote by clicking on one of the button,
you can see it tries to, it takes a while, and after a while, it fails.
And I can now see that there's an internal server error.
It says the server encountered and internal error and was
unable to complete your request.
If I go back and look at the logs, I see that it failed at
the line redis.rpush.
So basically it's unable to establish a connectivity to the
Redis, obviously, because we haven't run a Redis instance.
[No audio]
So what we're going to do now is I'm just going to kill that
instance, and I will first start a redis Container.
So I will run an instance of redis, and I will name it redis
[No audio]
So it's pulling down the redis image and it's run an instance of Redis.
I forgot to run it in the background, so I'll stop that and run it again.
The -d for the detach option.
Okay, so when I tried that, it failed again because I had
already run it without the detached option.
So it already created a Container with the name redis.
And I'm trying to create another Container with the same
name, so it's preventing me from doing that.
So I'll have to delete that the previously created Containers.
So I'm going to run a docker rm command to delete the previously
created Container, and I'll run the same command again to
start a new instance of redis.
So I now have a redis instance running.
I'm now going to start an instance of my voting-app.
So I will run the docker run command with voting-app, and
I will publish the Port 5000.
I will also this time add a link to the redis server.
So I'm running a voting-app and and added a link using the
--link option and specified redis as we discussed in the
lecture. Okay, so it's running now.
I'm back to my web portal, and when I now try to cast a vote,
you see that it goes successfully and I get a tick mark back.
Now, this is because my Container I was now able to run establish
a connectivity to Redis.
So now we have successfully deployed Redis as well as the
voting-application.
We will now proceed to the worker and for the worker prerequisite
is to have a Postgres database.
So we will first deploy a postgres database instance.
I'm not really sure what is the version of Postgres that
this application requires.
So I'm going to go into one of the files here.
For example, if I go into the docker-stack file or a docker-compose file,
I should be able to find the image that they
used. So it's image 9.4.
So I'm just going to use that here.
I will name the instance db.
And so later on, I can use that to create a link.
And now, as you can see, it's running, the Postgres database
is now started, and it's running successfully.
I forgot to run in the background, so I'm just going to kill
that runs in the background.
Okay.
I hit the issue again about the duplicate name.
So I'm just going to delete the one that I created using
the docker rm command.
And I'm going to rerun the Postgres database in the detached
mode. So I now have the Postgres database running.
So if I do a docker ps, I see that there are three Containers
running. One is my voting-app, one is my redis, and the third
one is the postgres database.
I can now go ahead and deploy the worker.
So first I'll have to build the worker.
So if I go to the worker directory and I can see the contents
of the Dockerfile, make sure it's intact.
And I'm going to run the docker build command to create and
to build the Docker image for the worker.
And we'll just wait for that to finish.
Once that is finished, when we run the docker images command,
we are able to see all the images that are available and
our newly created worker-app image.
We will now run an instance of the worker-app.
Now, the worker-app needs two links.
1 is to the redis and another link to the postgres database.
[No audio]
Okay, so as soon as it runs, you can see that it's processed one vote.
So that is the vote that we casted earlier.
Okay. So now when I run docker ps command, I can see that there
are four Containers running.
So we have the worker-app ready.
The next step is to build and deploy the result-app.
So that's the last step.
So we will create an image for the result-app.
We will deploy it and link it to the Postgres database.
So we go into the code repository for result.
And I have all the application and Dockerfiles there.
I will make sure the Dockerfile is intact.
And then I'm going to run the docker build command to create
an image for this result-app, and I will tag it results-app.
It goes through all the Node.js related installation steps,
and finally it's completed.
So now I have a new image, which is the result-app.
I'm now going to run the result-app, but since it is a web
server, it has a Port requirement.
So it exposes Port 80, and that's where it listens, I'm going
to map Port 80 to Port 5001 because Port 5,000 on my local
host is already occupied by the voting-app.
So my result-app, I'd like to see it on Port 5001, so I'll
map, I'll publish the Port 80 to 5001, and I also need to
add a link because the result-app is linked to the db.
So I'll add a link for that.
Okay, so that should be it.
And I'm now going to hit enter, and I can see that the application
has started and it's connected to db, which is good.
And if I go to the web browser and and establish a connectivity
to Port 5001, and I can see the result page.
So this is the result page.
Since my vote was for cats, I see the 100% wards for CATS.
I could also go back and change my vote.
So if I go back and change my vote to DOGS, I see it's changed
immediately. So every time I change my vote, it goes through the full cycle.
The data goes through Redis, the worker processes it, updates
the database, and then it's finally shown in this result
page. So that's it for this demo, we took a look at the example-voting-app.
We understood the architecture of it, how it works, and we
also successfully deployed it with docker run commands using links.
Thank you very much for your time.
And in the next demo, we'll look at how to do the same with Docker Compose.
[Outro music]