(English) Stop Writing Dockerfiles - Use Docker Init - Most Useful Docker Command (DownSub - Com)

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 9

hello everyone my name is abishek and welcome back to my channel in this video

let's learn about a simple Docker utility but a very very powerful one Docker in
it lot of times devops Engineers ask me this question abishek how to write Docker
files when we are not confident about the application build process and we are
not sure what commands to run to build the application and execute the
application previously my answer was to sit with the developers try to understand
how to build the application what are the commands that are required what
dependencies you need to download to build the application get the information on
the command to run the application but now my answer is to use Docker init let's
see how Docker in it works and what all it can do for us so I have a very simple
application for this demo it's in my python for devops repository this
repository helps You Learn Python right from Basics if you are a devops engineer
all the devops related use cases I'll put the link in the description but today
we will focus on this particular folder simple python app it's a very simple
application where there is a app.py this is a flask python application and when
this python file is run it returns hello world and it runs on Port 8,000 there
is a requirements.txt file with requirements such as flask and other dependencies
that are required to run this application first let's clone this repository
right let's see the magic of Docker in it where right now this repository let me
get my terminal so I will clone this repo and let's switch to the directory
python for devops simple python app there is only python file and the dependency
file there is no Docker file there is no Docker compos file Docker in it is going
to create all that for us before that let's see if this application is actually
working or not because before we containerize it we want to make sure that the
application dependencies everything are perfect so I'll simply do Python 3 app.py
I have python installed on my machine you also need to have it and you also need
to run pip 3 install minus r requirements . tht now let's try Python 3 app.py
okay it says that application is running try to access it on Port 8,000 let's
try Local Host colon 8,000 perfect if I refresh hello world so the application is
running now let's proceed with containerizing it where assume I don't know how to
containerize a python application I don't know what steps are required how to
write the docker file what is the base image what port to expose how to expose
solution is just run Docker in it you can also use this for your learning
purpose not just only for creating the docker compost file or Docker file using
it in your actual environment but still you can also use it in your home
environment where you are learning Docker where you learning uh Docker compos
okay so it says this utility will walk you through creating the following files
Docker file Docker compost file a readme file which explains how to access the
container once it is running okay let's select the programming language Docker in
it supports all these programming languages that you see here by default it is
python it says it detected python it is asking to confirm okay it's python let me
confirm python version let me go with 3.1.0 Port 8,000 yes it is fine what is a
command that you use to run this application here let me give as Python 3 app.py
that's it see the Magic in fraction of seconds it created dot Docker ignore file
Docker file compose file and a readme file this read me file will simply tell us
how to access the container that's okay now because all of these things are
created let me try to use the docker compose file let me just run Docker compose
up hyphen hyphen build let's see if the docker compost file that it has created
is working or not oh before that let me show me let me show you the compost file
so everything else is commented basically there is only one service that is
running server build context which means that Docker file is available in the
same directory and it is mapping the port of your host with a container that's
all in the docker compost file rest all is commented there is no DB that we are
using so going back Docker compose up minus minus build hyphen build so the
docker compose is running and once it is done I expect perfect now is working
now the port mapping is also done 8,000 port on your host is mapped with the port
within the container so let's try to access the URL that it provided hello world
so we got the output here we did not write the docker file we did not write the
docker compos file everything is written by Docker in it let's also see how good
is the docker file that Docker init wrote for us I'm quite surprised when I
actually started using Docker in it because it took care of all the security best
practices if you watch carefully it is using a user like it created a user for us
so that the container runs as nonroot and it also took care of disabling the
password for that particular user along with that it is also considering the
size of the docker image it has you know mounted see this particular line here
where download dependencies as a separate step to take advantage of docker's
caching so it is also considering the docker caching it is considering the size
of your Docker image it is making sure that it follows the security best
practices when I executed Docker in it against one of my go repository I also
noticed that it is creating the docker image sorry the docker file with multi-
stage Docker build concept here the application is a very simple one there are
not many dependencies while building the application so it just used one single
stage and in the beginning it choose the docker slim image but when you go for a
complicated project have also noticed that it is using multi-stage Docker with
the dless image concept so it's a quite interesting utility of course when I used
it against a super complicated project that I have which I'm using in XY Z place
I noticed there are some changes that I had to make but it is okay because it is
doing a lot of heavy lifting for me in simple applications it is working as
expected in complicated cases I had to make little tweaks but overall I have the
docker file created I have the compost file created so if I am a devops engineer
and if I have to containerize the projects Docker in it would be my goto solution
then probably I might sit with my developer trying to understand if everything uh
is perfect all the dependencies are as expected you know I would ask my
developers to just test this uh container on a local environment or a developer
environment but otherwise this utility is quite interesting it is available in
the docker desktop 4.18 and a versions so you need to have Docker desktop on your
machine and you need to have it with 4.18 or E versions I also see Docker
focusing a lot on it there is active development that is going on so this is
something that you all should watch out for I hope you like this video thank you
so much for watching it see you all in the next one take care

You might also like