Developing End-to-End NLP text generator application(part 3) — Using Docker and deploying app locally

Kevin MacIver
4 min readApr 30, 2020

This is the part 3 of a series of stories to show the steps to develop an end-to-end product to help write news articles by suggesting the next words of the text.

On part 1 we focused on generating a Bidirectional LSTM model, check out this link if you haven’t seen it yet:

On part 2 we focused on creating a full-stack application with FLASK, check out this link if you haven’t seen it yet:

Now that we have structure our full-stack application with frontend, backend and reverse-proxy we can put each part into a separate docker containers.

Which begs the question:

“What is a docker container?”

From the Docker documentation:

“A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.”

So a container has everything you needs to run your application, guaranteeing that the configurations are always the same and your application is portable.

Docker Images

Containers are built based on what are called images. These images are defined by a Dockerfile.

If we remember the tree structures of our project, shown on part 2, we’ll see that each folder has its own Dockerfile.

tree structure

API

The api Dockerfile is the following:

api/Dockerfile

The FROM command specifies the Parent Image from which you are building. In our case we need a python 3.7 image. Eventually you could choose a ubuntu, windows, or another parent image to build onto.

The WORKDIR sets the working directory for any run, cmd, copy and add instructions that follow it in the Dockerfile.

The ADD instruction copies new files, directories. Therefore in this case we are copying the content of the api folder.

The RUN commands install uwsgi and the libraries set in the api/requirements.txt.

The CMD execute the uwsgi protocol set in the api/app.ini file

CLIENT

The client Dockerfile is the following:

client/Dockerfile

The file follows the same commands as the api/Dockerfile

NGINX

The nginx Dockerfile is the following:

nginx/Dockerfile

The nginx/Dockerfile starts by loading a nginx image then removing the .conf file from the image and substituting it with our nginx.conf file.

With the three Dockerfiles presented we can build the images to generate each respective container. However, we still need to declare the ports we want to expose for each container in order to allow communication between them.

One approach could be modifying each docker file, build the images and start the containers individually. Another approach is to use docker-compose to tell the docker which image to build and the start order of each container.

Docker-Compose

To enable the use of docker-compose we need to build a docker-compose.yml file as a set of instruction to docker.

docker-compose.yml

The file begins by specifying the api image build and exposing the port 8080 for that container. Then we specify the client image build, exposing the port 6060 and declaring that this container is linked to api so, so api container must be up before client is. Lastly, we specify the nginx container and set the external port to 9080 and route it to port 80 of this container.

This basically states that all traffic through port 9080 is assigned as port 80 of the nginx container.

Deploying Locally

Now that our application, container and docker-compose files are defined we can deploy the app locally by running the docker-compose build and docker-compose up commands.

Conclusion of Part 3

Yeah, we got to deploy our app locally using docker. 🐋

On part 4 we will see how to create pods and deploy our app to the internet using kubernetes in google cloud.

Thanks for reading!

--

--

Kevin MacIver

Driven for innovation, waiting for the robots uprising..