DEV Community

Cover image for #009 Dockerfile
Omar
Omar

Posted on

#009 Dockerfile

Introduction

this is part 9 from the journey it's a long journey(360 day) so go please check previous parts , and if you need to walk in the journey with me please make sure to follow because I may post more than once in 1 Day but surely I will post daily at least one 😍.

And I will cover lot of tools as we move on.


setup

first go to DevOpsJourney folder on github .

GitHub logo khatibomar / DevOpsJourney

this is the repo where I will store all the codes used in our journey on dev.to

link

and open terminal then type

git clone https://github.com/OmarElKhatibCS/DevOpsJourney.git
cd DevOpsJourney/app_009
Enter fullscreen mode Exit fullscreen mode

a look inside the folder

Alt Text

now we have the files for this lesson ready to work on.


Dockerfile

A Docker File is a simple text file with instructions on how to build your images.
and he apply the commands from top to down step by step.
And it's good to mention that every step stored as a layer , so if you change something on line 4 , the line 1 to 3 will be cached so he will not execute them.
So the builds will get faster and faster in case of any change.

let's take a look of what inside our Dockerfile in the project that I made special for this part (app_009)

Alt Text

let's start break it line by line :
in line 1 I am asking docker to go and get the image of python with tag 3.9-rc-alpine
tag

in line 3 I ask him to RUN mkdir
RUN executes the command(s) that you give in a new layer and creates a new image. This is mainly used for installing a new package.

in line 4 , WORKDIR mean that from now all things I do it will be excuted inside the app folder . like cd but it doesn't change until I change the WORKDIR again.

in line 6 COPY mean copy the requirements text from the folder to the image in app folder (COPY FROM TO)

in line 7 it's will run the line "pip install -r requirements.txt" it's an python cmd to install the dependencies listed in the requirements text. (requirements.txt in the app folder inside the image)

in line 9 COPY . . , it means that copy all the folder containing to the app folder ( . mean the folder that I am inside)

in line 10 LABEL is an META DATA , so it give more information about the docker image.

in line 12 CMD is the default command to be run by the entrypoint. It sets default command and/or parameters, however, we can overwrite those commands or pass in and bypass the default parameters from the command line when docker runs.
python app.py is to run the script that I made.

Top comments (0)