Personality Prediction System End to End Deployment on Docker
In this tutorial, we will be looking at how to get our predictor system previously hosted on the AWS EC2 instance but now on Docker
This is actually a follow up on part-1 of the tutorial series where we deployed the system on Flask . I would recommend you to first give that a read — https://jinooo.medium.com/personality-prediction-system-end-to-end-deployment-on-flask-10d1af9faf78
What exactly is Docker?
In very simple term, Docker is a tool that packages all your code and dependencies to save you the trouble of portability along with reliability of running the code. All the code inside live in an isolated environment. Using docker, what works on X’s local end will work exactly the same on Y’s local computer.
Although this sound very similar to Virtual Machines, they entirely aren’t. First of all, they don’t need a separate Operating System. They share whatever resource is available on your PC and don’t need a separate allocation of resources.
Docker mainly has two main elements — Images and Containers .
Image is the actual package and it is more like an artifact that you can move around.
Container is basically an image but when run, it starts the application inside.
I’d advice you to go through the basics before continuing with this blog. Here’s a great place to start — https://docs.docker.com/get-started/
Creating a Dockerfile
A dockerfile is like an instruction page where you write down different commands that help in assembling the final image.
We will first navigate to the where the project folder is and create a file named Dockerfile with no extension. All we have to do is write 4 lines to build our image
FROM continuumio/anaconda3
WORKDIR /home
COPY personality .
CMD [“python”,”app.py”]
The first line is the base image and I’m using anaconda since it has pretty much all the libraries we need.
In the second line, we are telling to work from the directory home inside the docker container.
The third line copies all the files from the local end to the home directory of the docker container.
The final line executes ‘python app.py’ when the container starts running.
Now build the image
docker build -t personality_app
Creating container from the image
docker run -it -p 8888:8080 personality_app
The -it tag tells to run the container interactively so we can see the logs.
The -p tag is a port where we use the 8888 port from our local machine to forward all the requests from the 8080 port running in the docker container
(my bad I forgot to take a screenshot here ‘:(
After this, you will see the app boot up . Just go to your favorite browser and put down this url — http://127.0.0.1:8888/. And nowwwww
Whuhuuuu, you can now make your predictions here!
Pushing your image to the Docker Hub
Now if your team wants to have a look at that lil app of yours that you’ve just made, you can simply do this by pushing your image to the docker hub.
- Make a Repository
You need to first create an account on Docker hub and then click on the repositories tab to make a new one.
2. Go to your command line terminal for some magic magic
You need to first login. Do this by
docker login
Then you need to retag the previous image name to match the repository’s name. For that, you can
docker tag {prev_image} {docker_id}/{repo_name}
Finally, you are now ready to push.
docker push {docker_id}/{repo_name}
You can now see this on your repo page on docker hub.
Clicking on Public view
Now, anybody who wants to use this can simply docker pull jinorohit/my_personality and then be able to make cool predictions :)
That marks the end of my three part tutorial series on deployment. Feel free to ping me for any help.
Find me at — https://www.linkedin.com/in/jino-rohit-6032541b5/