How to “Dockerize” Your Python Applications | How To Build And Run A Python App In Docker Container

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and now in this video we will talk about how we can create the docker file for the python image okay so here you can see the different uh keywords I have written for you all okay so these are the some keywords which we use for creating the docker file actually so in this particular video basically we'll be will be creating the python image okay so uh here you can see actually the uh the description is also written for these keywords you can see the from keyword is used to use the base image okay what are the base image which we are going to use here so mostly in the from keyword we specify the base image for python we use Java for sorry for python we'll be use Python base image for Java we will be using open jdk for the Ubuntu will be us Ubuntu image okay so these are all the base images which we get from the docker we will be using those kind of images okay and run command is also used to run some kind of commands which we which you want to uh run while creating the container and all and copy used to copy the files from the local file system to the docker image work Dr used to set the working directory for the container actually okay and CMD is we use to CMD is basically used to specify the what are the commands you want to run or when that particular container runs or something like that happens okay so these are some of those uh I think three to five uh commands or keywords which will be using in our Docker file okay before starting the video or you should have uh vs code installer you can use any uh any uh ID not ID it's just what do we say or something like that okay or editor you can say so here I have this Docker Docker tutorial folder and I'll be creating one python image folder okay so let me just cancel all those things and now what we will be doing we will just create one Docker file okay you can do like this Docker file and keep it keep in mind like you should use only one capital D here not the name should be like this only okay so you here is the docker file has been created and let me create some app.pi as well okay so this is the python file and suppose you want to just print like this this is my first image okay cool so this is done suppose till uh now we just want to print this in our container like when our container will run okay now what we will be doing we'll be creating the docker file how we can do it you have to just use form and where from where I from which uh base image you want to use I want to use Simple python okay you can use from python after that you can specify the working directory for that particular container so I just want working directly to be app okay and also you want to copy all the files okay to the app here okay and next we'll be using the CMD okay now currently we don't want to run any kind of command okay that's why we are not using run here so in CMD what we want uh we want to use this line Python 3 and you can specify in a comma you want to run which file I want to run app.pi file okay so this one is done okay that much is fine to create the python image okay so now the further step is just to use to build that build image okay actually from the docker file so you have to just open up the terminal here you can click on this and click on this here talk a terminal and you have to go in that particular directory so we are currently in Python image so we are here in the directory and for building the uh image the command which we use is docker build and one hyphen T flag is used to define this some kind of tag like the default tag which you get is the latest so here you can Define any tag suppose like my first python app and in that also it should be only in lower case you cannot give the combination of a percussion lowercase in the tag name okay and then we will be using dot dot will be used to just uh get the docker file and then creating that image from that okay just hit enter and here you can see our image has been created actually and this one you can see exporting layer writing image this one okay naming my first python app this is done okay now I will just clear the screen I will just run that particular so image name was my I think first python app so it's running so here you can see it is printing this is my first image okay and if you go on the docker desktop so here also you will see the name is this one it is just specifying that random name it specifies and the image name in my first python app and image also here you can see the my first python app okay so in this way you can create the python image now let's do uh some what we can say uh some kind of experi not experiment just I write some commands actually here import OS okay and I want to just show you the actual uh directory in which directory that Docker is running okay so here we can write current dir is and here comma separator OS dot get CWD and here we will be using this one and again I want us to run the build image and I will build it okay and the container name I want to provide I want to provide name of container is iPhone iPhone name and it should be like uh uh what should be the name uh first pi first Pi c means first python container just hit enter and here you will see the this is my first image printing and currently I already slash okay and here if you will see uh here also like okay none it's showing we will see why okay tag is none okay okay no problem in containers if you see yeah engineer her name is first Pi C okay the container name actually okay so uh now what we will do uh again if you want so I just want to create one file here suppose I create one file Hello dot txt here and I just print hi here and I want to print the list of directories or files which are present in that documentary because we are using the copy here okay so it will copy all those things in the docker image so for this we can use OS dot get uh not get I think it's list dir yeah again we will just uh here I use some different tag uh list list I just do list image okay okay and now I run this using list image and the second Pi container enter and here you can see it is listing the all the uh what you can say um all the files and the current directory and the print statement is printing okay so in this way you can create the uh any python image which you want and suppose you want to uh send this file or something like that Suppose there is some kind of project which you have created in that file and you want to send to the other person so you can just create the image of that file and you can send it okay so in this way it works so I hope you like this video and that's all for today's videos guys and if you have any queries you can ask us in the comment section okay so that's it for today we'll meet you in the next video thank you for watching
Info
Channel: ProgrammingKnowledge
Views: 38,886
Rating: undefined out of 5
Keywords: dockerfile python example, docker image python, python dockerfile, dockerize python script, docker python tutorial, python dockerfile example github, docker compose python, python docker module, mysql QT sample code, Containerize a Python Application using Docker
Id: KUECJHlV1LE
Channel Id: undefined
Length: 9min 32sec (572 seconds)
Published: Sun Apr 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.