Build Your First Docker Image
Your First Dockerfile
We'll cover the following
In the last lesson, we saw how to run an app using a virtual environment. In this lesson, we will automate the steps required to run the app. We will do it with the help of Docker.
Clone the project using
git clone https://github.com/venky8283/Docker.git
Type
git checkout d469419582ee877067f6d449c9691ad16e5f3365
to get to the code used in this lesson.
The Docker engine executes all commands on your behalf, but we need to tell Docker what commands we want to execute. So, Docker has something called a Dockerfile. All the steps mentioned in the Dockerfile are executed step by step as we saw in the Docker fundamentals section. Create a file named ‘Dockerfile’ at the same level as of the app.py file. Dockerfile will have no extension.
Writing a Dockerfile
While writing a Dockerfile, we start with a main dependency of the app. Docker runs your app independent of platform. So, can you think about the main dependency of our app? What is the first thing you need to run your app?
This task is like finding the root of all the dependencies. Any luck?
Well, our app needs a Python environment. So, we need a base of Python on which we can build the stack required for our app.
So, the first command to Docker would be to get Python.
Get hands-on with 1400+ tech skills courses.