Three Tier Web API in Docker

Young(ish) man discovers the the power of containerization when deploying three tier web applications from scratch with docker-compose!

Let’s begin….!
You will need to clone a couple of repos from my github account. Pets-api is the API application and the database. Paw is the web server.

Once you have the repos cloned to your docker server, you will need to build the Docker images of the API server and the Web front end

On a docker server…!
Naturally, you will be running this on a docker server and we will be using docker-compose to bring up the infrastructure. Let’s navigate to the pets-api folder, the docker-compose YAML file has a couple of services it will start up. One is the “web” which represents the API server running on port 8088 and a “db” which is a mongo database.

Since the API has to connect to the database we will need to start the database container first sudo docker-compose up -d db. You can check to see if the database container is running by sudo docker ps. Now we can safely bring up the API server with this command, sudo docker-compose up -d web.

Now we should have two containers running and the API server is exposed to the outside world on port 8088. The last thing we have to do is get the web server running. The Paw container can be started by changing directory to the Paw dir and running this command sudo docker-compose up -d paw. If everything started correctly, you should have three containers running like this and the paw web server should be exposed on port 8080:

We are getting close to wrapping this up, just a few more things to do. The Paw webserver has a login page but we are going to have to seed the credentials. I have created a little utility called and you will need to run it with no arguments.Make sure you are in the PAW directory and run this command. python3, you will see a return code of 200 if everything is working.

Now if you want some actual store information in the database, you can bulk load some test information with another little utility. Issue this command. python3 Next, point your broswer to the localhost:8080 to see the main login screen for Paw.

This is the main web application. It is a work in progress. Only item that is functional is the list stores action.

Wrap it up by navigating to the stores/list menu item.

This list of stores was pulled from the mongo database and passed to the web service.

Quick demonstration.

Leave a Reply

Your email address will not be published. Required fields are marked *