Deploy to AWS, Docker in 10 Minutes!

Milan McGraw
Geek Culture
Published in
4 min readJul 5, 2021

It might be 4th of July, but I am not going to end today without a deployment!

Containers, Images, Dockerfiles, oh my!

Let’s get to the point, you just finished up your model and need it deployed, so let’s get to it. What is Docker and why do we need it? Docker is the de facto standard to build and share containerized applications. Docker let’s you deploy code quickly and significantly reduce the delay between writing code and running it in production. Once your team has developed an application/model, the next phase is deployment, with the end result being a service or app in a production environment that can be accessed by your customers.

So in the next 9 minutes, I will cover Docker for Application Deployment.

First, let’s review the terms….Docker Objects

Container — A container is a runnable instance of an image.

Docker Image — A Docker Image is a read-only template that enables the creation of a runnable instance of an application, specifically a docker image provides the execution environment for an application, any essential code, config files, and dependencies that are used to spin up a container.

Dockerfile — A Dockerfile is a simple set of instructions used to create a Docker image.

Now let’s put this all together.

To construct a Dockerfile, use these predefined instructions::

FROM -        to set the base image
RUN - to execute a command
COPY & ADD - to copy files from host to the container
CMD - to set the default command to execute when the container starts
EXPOSE - to expose an application port

Below is an example of a Dockerfile that targets to package a python application (see for repo here):

# Simple Docker that aims to package a simple Python application (this same code will be use for the Fourthbrain.com Capstone deployment day July 8th, 2021).# The first instruction is FROM:  which specifies the base image as being Python in version 3.8FROM python:3.8

# Set and define the working directory which feature commands will be executed from /app
WORKDIR /app

# Copy will add the current directory contents into the container file system at /app
COPY . /app

ENTRYPOINT [ "python3" ]

# This file contains all the dependencies and libraries that your Python application requires to execute successfully.
RUN pip3 install -r requirements.txt

#Expose indicates the ports (in this case 8080) that the container should listen to for connections.
EXPOSE 8080

# The CMD command provides the command to run within the container when it starts.
# Run your application!
CMD ["run.py"]

Once the Dockerfile is created, now build the image.

What is a Docker Image again?

Docker Image — A Docker image is a read-only template that enables the creation of a runnable instance of an application, specifically a docker image provides the execution environment for an application, any essential code, config files, and dependencies that are used to spin up a container.

Now run your application…

The two most important lines of code are: 1st, Build the image and 2nd, to run the application.

1st — Build the image.

docker build -t app-basic .

2nd — Launch the container and bind the port 8080 the localhost of your machine.

docker run -p 8080:8080 app-basic

Wake up, are you still with me? Just like Emerald says like “Bam!”

Now you are up and running, navigate to http://localhost:8080 and view your live application.

Once you tested this on your pc and it runs — which means you are in business and the success of the app is now validated. Let’s keep it real, before distributing the Docker image to peers, it is paramount to test it locally and verify if it meets the expected behavior. You might also want to save your Docker image to a registry, but that is another topic for later discussion.

Next, now let’s get it distributed in the cloud and deployed for distribution.

Deploy to Amazon ECS

Next, upload your application folder to a ECS instance and deploy to your app to AWS ECS.

Docker Image uploaded to an Amazon EC2 Instance

Conclusion

So I explored Docker for your ML Application Deployment and a standard template for easy execution. Thanks to Tatiana Chebonenko who had to explain this to me like a 10 year old, twice — K.I.S.S. (just like in the Military)!

References

All the notes in this post were taking from a variety of sources and the class below: https://www.udacity.com/course/cloud-native-application-architecture-nanodegree--nd064, if you are interested in learning Deployment, I highly recommend you taking this course.

Dockerfile Reference docs: https://docs.docker.com/engine/reference/builder/#from

Stay in touch, Linkedin!

--

--

Milan McGraw
Geek Culture

Immensely interested in all things AI | You can’t become the best without first, being the worst. {So I will write to learn!!!}