Skip to playerSkip to main content
  • 6 months ago

Category

📚
Learning
Transcript
00:04Next, now we are going to start a very important concept which is called Docker Compose.
00:08Basically, now we have set up multiple containers.
00:12If we take a example of NodeJS application,
00:14we were running these commands
00:19where we were running a single container
00:21with the help of these complex commands.
00:23Now, when we run these complex commands in our terminal,
00:26it can lead to a lot of confusion.
00:28Especially, if we set up multiple containers.
00:31So, when we have multiple containers in our application,
00:35then we have to manage those containers
00:37we use this tool which is called Docker Compose.
00:40So, Docker Compose is a tool for defining and running multiple container applications.
00:44Basically, what do we do with Docker Compose?
00:47The whole process of running up and setting up multiple containers,
00:52we define it in the form of a single file.
00:56So, in the form of a single file, we have to set up multiple containers here.
01:06So, in the form of a single file, we can do some additional things in our container.
01:09So, in the form of a single file, we have to re-execute commands here.
01:12So, in the form of a single file, we have to change some changes here.
01:15And then, we have to save our file again.
01:16So, in the form of a single file, we have to save it and run it.
01:17So, the work we have done in the terminal for Mongo and Mongo Express.
01:21We are going to do that same work with the help of this file.
01:24Now, this file is a special file.
01:27which we know of YAML or .yaml file.
01:32.yaml basically stands for yet another markup language.
01:34So, this is a special file which we will create in our Node.js application.
01:39In which we will have instructions of running and setting up multiple containers in our application.
01:45So, basically, compose gives us a better way, a more structured way for running the same containers,
01:51which we have to run Docker command.
01:53So, YAML file is a way to see this.
01:57Where we define a version of the top.
02:01This version is basically an obsolete property.
02:03We do not define a new version of Docker Compose.
02:07But, on the top we define a version of Docker Compose.
02:09Basically, it is our Docker Compose version.
02:11We define a version of which we will run according to our commands.
02:16Now, as such, we will define which version here.
02:19We will define 3 or 3.8.
02:20There will be no difference between that.
02:22Because this is just an informative attribute.
02:24In fact, those students will be using the latest version of Docker.
02:27They will be able to throw a warning here,
02:29that the version needs to be necessary.
02:31But, we will define it in YAML.
02:33After that, what do we do in our file?
02:36We define our services.
02:37We define our services.
02:38When we think about services,
02:40we have to equate that
02:42the services basically means
02:43how many containers we want to create.
02:46We want to create the container.
02:48We want to define the services.
02:50We know that
02:51we have two containers to create.
02:53One is Mongo.
02:54And one is our Mongo Express.
02:57So, within our services,
02:59there will be our container's name.
03:02So, we will keep our container's name here.
03:05We will place our second container.
03:07We will place our second container.
03:07Mongo Express.
03:10So, this way,
03:11we start to make our different containers
03:12all specific specifications.
03:14Now, we will have to take an example of Mongo Express.
03:17This time we have to take our command.
03:19We need to make our file convert into the file.
03:21So, in the file convert into the file,
03:23we will place to create Mongo Express.
03:25Indentations, spacing very important to YAML.
03:28And that is,
03:34we will start by writing version
03:41let's suppose we have 3.8 version used
03:43we will start with the first service that we are going to create
03:53let's suppose we have Mongo Express
03:57now we will start with the entire environment variables
04:03and different properties
04:03the most common property is image
04:07which image is container we will write
04:09this is our container name
04:12we will write here
04:13which image is container we want to create
04:16so our image name is also
04:19we will simply write Mongo Express
04:22then we have one option
04:23restart always
04:25we want to skip it
04:27this basically means
04:28docker container is going to automatically restart
04:30when docker restarts
04:31we want to skip it
04:33then we will define our ports
04:34so to define our ports
04:37we will simply write ports
04:39and then hyphen
04:40so this port binding
04:41we have done it
04:42now we will write it in the file
04:44how do we write it in the file
04:45here we are going to define that
04:47we want to bind 8081
04:49with this port
04:508081
04:50then we will set up this way
04:52we will set up our environment variables
04:53so we simply write
04:56environment
04:56and
04:571-1
04:58we will define our environment variables
05:00and start
05:01for our Mongo Express
05:02we have 3 environment variables
05:04so first
05:05meconfig
05:06mongodb
05:07admin username
05:08so this is how we convert the entire docker command
05:24which we have run in the terminal
05:25to simple instructions written in a yaml file
05:28so if we want to run both Mongo and Mongo Express containers
05:32we will write in our yaml file
05:34before we are going to do something else
05:38which is basically to stop all of the containers
05:42so now we will stop both containers
05:44so we can write this
05:46so let us do
05:48docker stop
05:48mongo
05:49and our Mongo Express container
05:52which is run
05:54docker ps
06:04THAT
06:05let us clear this
06:13docker ps
06:14and AMAL
06:15If we want to check the images
06:19we can remove the images
06:22to the first image
06:24that we want to remove is this
06:26second image may be
06:28id paste it in the second image
06:31and now we have successfully
06:32deleted the images
06:33docker images also docker images
06:35so now we will not have anything
06:36now we will do this whole
06:37mongo and mongo express
06:38with the help of the yamil file
06:41so in node.js application
06:43we are going to
06:45let's clear this
06:46we are going to create our file
06:48and this file basically
06:50we will create our node application
06:52let us call it
06:54mongo.yamil
06:57mongo.yamil
06:59we will start writing our instructions
07:01so we will start by defining the version
07:04we can write the same version
07:06which we have used in the example
07:07which was 3.8
07:09and after that we will start by defining the services
07:12we will give a space of a tab
07:13and we will define our first service
07:15which is going to be mongo
07:18in the mongo service we have different
07:21attributes and properties
07:22we have to define
07:22so basically
07:24we have to run our mongo container
07:25we have to run all the options
07:27so now we are going to recreate them in the yamil file
07:31first of all we can choose the image option
07:34so we know that we are going to choose the mongo image
07:37after that we can define the ports
07:39ports
07:40so now we can use the 27017
07:44bind to the 27 017
07:46so in this way we will do our port binding
07:48in the yamil file
07:50next we are going to define the environment variables
07:53now we can define the environment variables
07:54now we can define the environment variables
08:08define होता है. दूसरा तरीका है, we define it with the help of colons.
08:12तो colon के बाद हम एक space देंगे and जब हम colons use कर रहे हैं,
08:16तो वहाँ पर हमें hyphen को use नहीं करना, simply एक space देनी है and उसके
08:20बाद we need to define our environment variables like this. Similarly, हम अपने
08:24next environment variable को यहां से copy कर सकते हैं and we can define it here
08:29with the help of this colon. और कोई option हमारे लिए as such बचा नहीं है,
08:34एक चीज़ बची है, वो है अपने network को define करना. अब वन वे आ ट्राइंग
08:38to run docker containers with the help of this yaml file, तो docker compose हमारे लिए
08:42automatically network setup करके and create करके दे रहा है, वहां पर हमें
08:47network asset setup करने की जरूरत नहीं पड़ती है, तो यहां पर हमें
08:50network को define करने की asset जरूरत नहीं है, now we can move on to the second
08:56service which is mongo express, mongo express के लिए हम जो image use करेंगे that is also
09:02mongo express, उसके बाद we can define the ports, ports के अंदर we are going to bind
09:088081 with 8081, हमारे फिर environment variables आ जाएंगे, environment variables के लिए
09:16सबसे पहले let us copy this environment variable and इसे यहां पर लिख लेते हैं
09:21with the help of this colon, उसके बाद हमारा second environment variable आ जाएगा
09:26which is the password, let us copy this and paste it here with the help of this colon
09:32and finally our URL इसे भी यहां से copy कर लेते हैं and इसे हम यहां पर इस तरीके से
09:39paste कर सकते हैं, हम चाहें तो अपने URL से we can remove the double quotes and last
09:44we can end with a slash, तो इस तरीके से हमारे पास MongoDB URL पूरा को पूरा
09:48setup कोई आ जाएगा and this is how we create a Mongo YAML command,
09:52अब next thing that we have to do is run our containers with the help of Docker Compose,
09:56तो Docker Compose की help से containers को run करने के लिए, we use this command,
10:00यहां पर हम hyphen भी लिख सकते हैं, hyphen को अटा भी सकते हैं,
10:02simply Docker Space Compose भी लिख सकते हैं,
10:05फिर हम अपना file option देते हैं, अपनी file का नाम देते हैं and then we define the action that
10:10we want to perform,
10:11generally Docker Compose के अंदर दो सबसे popular actions है, up and down,
10:14up वाला जो action है वो हमारे लिए हमारे सबसे पहले network को set up करेगा,
10:19हमारे Docker containers को set up करेगा, उन्हें running state के अंदर लेकर आएगा,
10:23जब हम down action perform करेंगे तो उसका मतलब है हमारे जो containers है,
10:27वो हमारे लिए permanently delete हो जाएंगे and finally,
10:30हम अपने containers को run करेंगे in the detach mode,
10:32तो यहां पर, since we are already inside the node application,
10:36जहां पर हमने अपनी yaml file को create किया है,
10:38तो हम directly अपनी Docker Compose command run कर सकते हैं,
10:42docker-compose-v,
10:44फिर हमारी file का नाम which is mongo.yaml
10:47and इसे हम action है,
10:49अब run करेंगे in the detach mode,
10:52तो let us enter it,
10:53सबसे पहले हमारे पास warning ही आई है,
10:55that the version is obsolete,
10:56जिसको हमने पहले भी बात की थी,
10:58कि यह version हम चाहे तो skip कर सकते हैं,
11:00यह as such latest,
11:01हमारे जो Docker Compose versions हैं,
11:02उसके अंदर useful नहीं रहता,
11:04हमारे लिए दोनों जो images हैं,
11:06Mongo Express and Mongo,
11:07दोनों को पुल किया जा रहा है,
11:09उसके बाद with the help of these images,
11:10our Docker containers will be set up,
11:12तो finally,
11:13तीन चीजें,
11:14इंटरेस्टिंग चीजें हमें देखने को मिलेंगी,
11:15सबसे पहले हमारे लिए Docker Compose ने अपना network हमें create करके दिया है,
11:19इस network को नाम दिया है node app default,
11:21उसके बाद it has also created these two containers for running Mongo and Mongo Express,
11:25you can also clear this,
11:27सबसे पहले तो अपना network जो है उसे verify कर लेते हैं,
11:30Docker, यह हमारा network था,
11:32जिसे हमने create किया था,
11:33Mongo network,
11:34यह हमारे लिए Docker Compose ने create किया,
11:36उसके अलावा,
11:37Docker PS अगर करें,
11:39तो यह हमारे दो containers है,
11:40in the running state,
11:41Mongo Express and Mongo,
11:43हम चाहें तो इन containers के logs भी चेक कर सकते हैं,
11:45तो docker logs,
11:47this is the container ID,
11:48तो Mongo Express के logs को हम चेक करते हैं,
11:51so these are the logs,
11:53यहां पर हमें पता चल रहा है कि बार-बार
11:54Mongo Express ने क्या किया है,
11:56Mongo के साथ,
11:57मतलब हमारा जो Mongo container है,
11:59उसके साथ connection बनाने की कोशिश की है,
12:02तो पहले connection refuse हुआ,
12:03connection refuse हुआ,
12:04connection refuse हुआ,
12:04connection refuse हुआ,
12:05इस तरीके से,
12:06उसके बाद finally connection established हुआ है,
12:08जिसके बाद Mongo Express Server
12:09started listening at port 8081,
12:12तो इस तरीके से हमारा connection
12:14जो है,
12:15established हुआ है,
12:16we can also verify this,
12:17कि हमारे जो container है,
12:18वो successfully setup होकर run हो रहे हैं,
12:21कि 8081 पर अगर हम जाएंगे,
12:23तो इस तरीके से,
12:24हमारे पास Mongo Express
12:25हमें run करता हुआ,
12:26अब एक और interesting चीज हो,
12:28जो हम note करेंगे,
12:29हमने जो पहले अपना sample database
12:31create किया था,
12:32वो अब यहां से completely delete हो चुका है,
12:34उसके delete होने का reason है,
12:48वैसे पुराना data,
12:49जो भी हमने database collections,
12:50हमारे documents create किये थे,
12:52वो सारे-सारे delete हो चुके होंगे,
12:53there is something called volume in Docker,
12:56जिसको हम use करते हैं for data persistence,
12:58जिसको आगे जाके हम cover करेंगे,
13:00पर अभी के लिए जब हम containers को restart कर रहे हैं,
13:02या नए containers create कर रहे हैं,
13:03महाँ पर database के अंदर कोई persistence नहीं,
13:05तो यहाँ पर दुबारा से,
13:07हमें वही same जो database है,
13:09वो create करना पड़ेगा,
13:11तो we have created the database,
13:13and इस database के अंदर जाके,
13:14हमें वही same collection create करना पड़ेगा,
13:17collection के अंदर we can create a new document,
13:19हम चाहें तो,
13:21एक new document create कर सकते हैं,
13:23with the same email or maybe a different email,
13:28email में let us suppose john at the rate gmail dot com,
13:34and हमारे पास एक username आ जाएगा,
13:37which will be john doe,
13:41and we'll have a password,
13:45that is going to be secret,
13:50इसे save कर लेते हैं,
13:51हमारे पास एक document आ गया,
13:52verify कैसे करें,
13:53node application के साथ,
13:54connection established हो गया है,
13:56यह हमारा पुराना data है,
13:57जब हम इसे refresh करेंगे,
13:59server start कर लेते हैं उससे पहले,
14:02node server.js,
14:04जब हम इसे refresh करेंगे,
14:06तो अब हमारे पास नया data आ गया है,
14:08जिसे हमने new insert किया था database के अंदर,
14:11तो इस तरीके से हमने अपनी yaml file की,
14:13यानि docker compose की help से,
14:15अब अपने containers को recreate कर लिया है,
14:17restart कर लिया है,
14:19and they are successfully working with our existing node.js application,
14:23तो इस तरीके से docker compose को हम use कर सकते हैं,
14:26अपनी commands को इस तरीके से file में हम लिख सकते हैं,
14:28जब भी हमें multiple containers के साथ work करना होता है,
14:31and finally,
14:32जैसे इन containers को हमने start किया था,
14:34वैसे ही हमने shutdown कर सकते हैं
14:35with the help of the down command,
14:37तो यहीं पर if we run the docker compose hyphen fmongo.yaml
14:43and अब अगर हम down action को perform करें,
14:46तो अब हमारे लिए सारे के सारे containers,
14:48in fact including the network,
14:50यह सारी चीज़ें remove हो जाएंगी,
14:52हम docker network ls अगर करें,
14:56तो अब हमारे लिए वो network भी completely gaire बो चुका है,
14:59and docker ps- a करें,
15:02तो हमारे पास containers भी नहीं है,
15:04in fact docker desktop पर जाकर we can also verify this,
15:07images हमारे पास हैं,
15:09क्यूंकि images को हमने use किया था,
15:10but वो containers अब हमारे लिए delete हो चुके है,
15:13so this is how we can delete everything with the help of this down command,
15:21next use case for docker that we are going to cover,
15:23is dockerizing our own application,
15:26basically,
15:27अभी तक हमने जो node.js application को built किया है,
15:29if this is our app,
15:31तो अभी वो हमारे local system के अंदर exist करती है,
15:33next हम क्या करते हैं,
15:35हम इस application को,
15:36we are going to convert it into a docker image,
15:39और फिर यह image है,
15:41जिसे हम अपने teammates के साथ share कर सकते हैं,
15:43दूसरे लोगों के साथ share कर सकते हैं,
15:44या फिर इसी image का,
15:45हमें container run कर सकते हैं,
15:47basically, जिस application को,
15:49नोट जिस application को,
16:01we are going to convert this application into a docker image,
16:04अब generally, if we talk about the production environment,
16:07तो यह जो काम होता है,
16:08हमारी CICD pipeline के अंद,
16:09Genkin नाम का एक tool होता है,
16:11जो automatically हमारी जो application होती है,
16:13उसे एक docker image के अंदर convert करता है,
16:14और फिर उसी image को push किया जाता है,
16:16to a public repository और maybe a private repo,
16:19तो इस तरीके का prod environment के अंदर,
16:21हमारा flow होता है,
16:21पर यहां पर हम कोई tool use नहीं करेंगे,
16:24यहां पर हम खुदी जाकर अपनी इस application को package करेंगे,
16:27into a docker image,
16:28अब the process of converting our application into a docker image,
16:32is called dockerizing our application,
16:34और अपनी application को dockerize करने के लिए,
16:37we use something called a docker file,
16:39docker file basically,
16:41a special file होती है,
16:42जिसके अंदर instructions होते हैं,
16:44कैसे applications को docker image के अंदर हमें convert करना है,
16:47so this is a very special kind of file,
16:49जिसे हम अपनी node.js application के अंदर ही create करते हैं,
16:52so this file is basically like a blueprint to create our docker images,
16:56अब if we want to see what a docker file looks like,
16:58तो हमारी docker file कुछ इस तरीके की दिखाई देती है,
17:01जिसके अंदर we have different different commands,
17:03जो बताते हैं हमारी docker image को किस तरीके से setup करना है,
17:06if we talk about the different commands,
17:08तो है पूरी की पूरी जो documentation है,
17:10it is also available on docker docs,
17:12so we can go to this link,
17:14and यहां पर हमारी जो common instructions है,
17:16जो docker file के अंदर include होनी चाहिए,
17:18उनके बारे में हमें details में जाएंगी,
17:20सबसे पहली,
17:21सबसे common instruction एक docker file के अंदर होती है,
17:23from instruction,
17:24from instruction के अंदर हम अपनी base image को define करते हैं,
17:29अब what exactly is this base image,
17:31basically हम लिखते हैं from,
17:34and उसके बाद we define our base image,
17:37base image के बारे में हमने पहले भी discuss किया था,
17:39when we talk about the layering of images inside an image itself,
17:43inside a docker image,
17:44basically base image को हम इस तरीके से imagine कर सकते हैं,
17:47कि अगर हमारी application है,
17:49जो एक node.js application है,
17:51उसे अगर हमें run करना है,
17:52तो run करने के लिए हमारे system के उपर already existing क्या चीज़े होनी चाहिए,
17:57हमें पता है हमारी node.js application के अंदर ये सारी चीज़ें exist करती हैं,
18:01पर क्या हम कह सकते हैं कि हमारे system के अंदर ये पूरा folder की सारी files
18:05run करें, उसके लिए system के अंदर node का install होना बहुत ज़रूरी है,
18:10तो हमारी application के लिए,
18:12जो base image होगी,
18:13that will basically be a node image,
18:16कि हमारे system के अंदर node installed है,
18:19तभी app run कर रही है,
18:21तो हमारे पास Docker के अंदर,
18:22base image जो हम install करेंगे,
18:24वो node की image होगी,
18:26मतलब node के जितने भी tools and technologies हैं,
18:28वो हमारे Docker container के अंदर already set up होगी,
18:31तभी हमारी इस application का container,
18:34वहाँ पर successfully run कर पाएगा,
18:35so this is the concept for the base image,
18:37यहाँ पर यह जो example है,
18:38this is of a flask based application,
18:40तो इसलिए यहाँ पर base image है, python,
18:42तो python का एक specific version है,
18:44जो हाँ पर install किया जा रहे है,
18:45यह उसे base image की तरह define किया जा रहे,
18:47work directory instruction से,
18:49हम basically अपनी working directory को define करते हैं,
18:52तो working directory और the path in the image,
18:54where files will be copied and commands will be executed,
18:57उसके बाद हमारे पास एक और important command होती है,
19:00which is the copy command,
19:01copy command, जब भी हम लिखते हैं,
19:04if we write copy,
19:05तो basically हमारे host से,
19:08हमें host से,
19:09जो भी files copy करनी होती है,
19:11उन्हें हम बताते हैं कि अपने container के अंदर,
19:13जो भी हमारा Docker container बन कर आएगा,
19:16उस container के अंदर हमारे
19:17कौन से path पर वो files copy होनी चाहिए,
19:20जैसे example के लिए,
19:21अगर यहां पर लिखा हुआ है, copy,
19:24requirements.txt,
19:25तो basically हम इस file को,
19:28अपने container की,
19:29इस file के अंदर copy करना चाहते हैं,
19:31हम चाहें तो file को file में copy कर सकते हैं,
19:33या काफी सारे files and folders को भी
19:35किसी एक particular folder के अंदर copy कर सकते हैं,
19:38तो हम चाहें कि,
19:39जब हमारा Docker container बने तो हमारी यह सारी
19:41की सारी files हमारे उस container
19:43के अंदर जाकर copy हो जाएं,
19:45तभी तो वो वहाँ पर run कर पाएंगी,
19:46उसके साथ में we also have the run command,
19:49run command से basically we give instruction,
19:52we tell the builder to run the specific command,
20:03before the container starts,
20:05यानि जब भी Docker container को आमे
20:07build करना होगा, तो उस time पर हमारी यह command
20:09run करेगी, तो run command basically
20:11वो instructions देती है, जो Docker image
20:13build होते time, जिन instructions को
20:15सब को run होना है, तो हमारे code के अंदर,
20:17यानि हमारी Docker file के अंदर,
20:19हमारे पास multiple run commands हो सकती है,
20:21इसी से मिलती जुलती एक और
20:23important command होती है, which is called cmd command,
20:25अब run and cmd command,
20:27दोनों काफी similar सी दिख सकती है,
20:29but the difference is, कि हमारी
20:31Docker file है, उसके अंदर बहुत
20:33सारी run commands हो सकती है, but
20:34सिर्फ एक ही cmd command होगी,
20:36cmd command basically is the instruction
20:39that sells the default command
20:40a container using the image will run,
20:42basically हमारी Docker image
20:44हम create कर रहे हैं, जब इस Docker image
20:46का container बनेगा, तो container
20:48के start होने पर एक single command है
20:51जो run हो सकती है, वही हमारी
20:52cmd command होती है,
20:54for example, if this is our node.js application,
20:57हमने पूरी application को setup कर लिया,
20:59पर setup करने के बाद अपनी application
21:00को run करने के लिए, हमें अपने
21:02terminal के अंदर लिखना पथता है,
21:03node.server.js, तो यह एक
21:05command है, जो run करेगी
21:08सारे के सारे setup को,
21:09so, हमारे case में, this is
21:11going to be our cmd command, cmd
21:13command एक ही होती है, इसके
21:14साथ में, we also have expose instruction,
21:16जिससे हम किसी भी port को expose कर सकते हैं,
21:19we also have env instruction,
21:20जिससे हम अपने environment variables को set
21:22कर सकते हैं, that a running container
21:24will use, मतलब, अभी build हम
21:26image कर रहे हैं, बट जब इस image का container
21:28run होगा, तो उस time पर कॉन-कॉन
21:30से variables होने ही चाहिए, environment variables,
21:32उन्हें हम पहले से ही
21:34अपनी docker file के अंदर कुछ इस तरीके से
21:36define कर रहे होते हैं, so this is the basic
21:38syntax of writing things in a docker
21:40file,
21:44अब हम चाहें तो खुद की
21:46अपनी docker file create कर सकते हैं, docker
21:48file को हम उसी application के अंदर create
21:50करेंगे, जिसे हमें dockerize करना है,
21:52so let us create a new file,
22:00and this is how we create
22:02a docker file, you can also install
22:04docker in vs code, पर उसे
22:06अभी के लिए हम install नहीं करने वाले,
22:07so docker file के अंदर सबसे पहले हमें
22:09base image define करनी होती है, with the help of from,
22:11so from के बाद हमारी जूभी base image है,
22:13हमें पता है हम node use करने वाले है,
22:16so हम node.js की base image
22:17use करेंगे, which is node, we can also search
22:19for this image on
22:21docker hub,
22:23so if we look for node,
22:25तो हमारी पास
22:26यह image है, जो हम basically
22:28हमारी base image बनेगे, अब node के अंदर भी
22:30different different versions available होती है, for example
22:3223.7.0
22:34slim, तो हम यहां पर चाहें, तो अपने
22:36tags भी define कर सकते है, 27.3.0
22:40slim, इस तरीके से, I think
22:42this is the same thing, तो इस तरीके से
22:44हम अपने different different versions या tags
22:46के साथ भी अपनी base image को define कर सकते है
22:48अब यह जो base image को define
22:50करने का पूरा का पूरा process है,
22:52यही हमारी docker images के अंदर
22:54layering create करता है, कैसे हमारी
22:56layers को create करता है, उसे एक बार समझते है
22:58basically, अभी हम क्या कर रहे है
23:00अभी हम अपनी एक application है
23:02यह docker image है, जिसे create करने की कोशिश कर रहे है
23:04हमारी यह application है
23:06let us suppose, इसे हम देंगे
23:08version 1.0, क्योंकि यह
23:10हमारी node.js based application है
23:11अब इस node.js based application के लिए
23:14हमने क्या किया है, अपने लिए
23:15base image define की है, कि हम
23:18अपनी node base image को
23:20use करेंगे, यह example के लिए
23:22ले लेते हैं, कि हम अपने
23:23इस tag को use करने वाले है
23:25which is 2723.7.0
23:29slim
23:29let us suppose, हम node का यह version
23:31use करेंगे, तो 27.3.0
23:35slim
23:35तो क्या हम कह सकते हैं कि हमारी application
23:37इस layer के ऊपर based होगी
23:39and internally अगर हम देखें
23:42तो हमारा यह
23:43version है node का, यह
23:45अपने आप में एक दूसरी
23:47base image use करता है, which is a
23:49Linux based image, तो यह
23:51debian का version या tag
23:53bookwarm slim को use करता है
23:55मतलब खुद node क्या कर रहा है,
23:57खुद node एक और base image use कर रहा है
23:59which is a debian
24:01distribution
24:03bookwarm
24:05slim
24:07या in fact इनके अगर versions
24:09अभी के लिए हटा दें,
24:11example के लिए, तो क्या हम कह सकते हैं कि
24:13हमारी application एक base image
24:15use कर रही है, node
24:17node अपनी आप में एक और base image
24:19use कर रही है, which is a Linux distribution
24:20debian, तो इस तरीके से जब हम
24:23अपनी application को dockerize
24:25कर रहे हैं, उसकी docker image बनाने की
24:27कोशिश कर रहे हैं, तो हमें दिखराए
24:29कि image किस तरीके से layers में
24:31बिल्ड होती है, हर image की
24:32अपनी एक base image होती है, base image
24:34मतलब basic चीजें जो हमारी
24:36उस image से आएंगी, जो already
24:38हमारी application के लिए set up होनी चाहे
24:43तो यहां पर भी हमारी एक तरीके से
24:46layering है, जो चल रही है
24:48तो we are going to
24:49build our image from note
24:52उसके बाद अपनी application को run करने के लिए
24:54हमारे पास दो environment variables है
24:56जिनको हमें define करना पड़ेगा, एक हमारा
24:58environment variable है, हमारा admin username
25:00and एक हमारा admin password
25:02जो हमें mongodb database
25:04के अंदर help करेंगे, तो अपने environment
25:06variables के लिए we are going to write
25:08mongodb
25:10username and equal to करके
25:12हम अपने environment variables की value दे
25:14सकते है, delta
25:16admin and we are going
25:18to define one more environment variable
25:20which is mongodb
25:22password, password की value हो
25:24जाएगी delta
25:26password, तो इस तरीके से दो environment
25:28variables हमने setup कर दिये, अब
25:30हमें command को run करेंगे, command
25:32basically to create some files
25:34or create some folders in our container
25:36यह command basically
25:38define कर रही है कि image कैसे बनेगी
25:40और कल को अगर container run होगा
25:42तो container के अंदर क्या-क्या चीज़े होगी
25:43तो हम इस तरीके से imagine कर सकते हैं कि
25:45container के अंदर क्या-क्या होगा
25:47हमारी application run होने से पहले
25:48हम वो सारी चीज़े यहां पर define कर रहे हैं
25:52अंदर हम एक नई
25:54directory जो है उसे setup करें
25:56and उस directory का हम
25:58नाम रखें delta-app
25:59basically हमारे container के अंदर
26:02delta नाम के एक directory आजाएगी
26:03और इस app के अंदर हम अपने
26:05सारे के सारे files and folders
26:07मतलब जो यहां पर available है उन सब को इसके अंदर copy करतेंगे
26:10हम इसे app नाम दे सकते हैं
26:12या हम इसे sample या
26:14node.js, node.app नाम दे सकते हैं
26:16जो नाम हमने यहां पर दिया है
26:17उसके बाद we are going to use the copy instruction
26:19copy instruction का मतलब है
26:20एक बार यह जो folder है
26:23वो हमारे container के अंदर बन गया
26:25अब हमें अपने local system की files को
26:27अपने host system की files को
26:29इस container के अंदर copy करना है
26:31तो copy करने के लिए क्योंकि docker file कहां पर है
26:33node.app के अंदर है
26:34तो हम सिर्फ dot लिखेंगे
26:36मतलब यह सारी की सारी जो files है
26:38यह कहां पर copy करनी है
26:39यह हमें delta के अंदर अपनी node.app के अंदर ही
26:43जाकर copy करनी है
26:44in fact this will be hyphen delta hyphen node.app
26:47तो सारी की सारी files हमारे host system से
26:50हमारे docker container के अंदर
26:52जाकर copy हो जाएंगी
26:53और एक बार हमारी files copy हो गई
26:55node.js already set up है
26:57सारी files हमने copy कर लिए
26:58finally हम अपने server को start कर देते हैं
27:01तो cmd के अंदर
27:02अपनी commands को लिखने का specific तरीका होता है
27:04basically we write cmd
27:06and उसके बाद
27:07हम इस तरीके से अपनी सारी के सारी
27:09individual commands को separate करते हैं
27:11in the form of strings
27:12तो अपने इस array के अंदर
27:13सबसे पहले हम pass करेंगे
27:15node, उसके बाद हम pass
27:17करेंगे server.js
27:19और यह जो server.js होगा
27:21यह हमें पता ही कि already हमारे
27:23docker container के अंदर आ चुका है
27:25docker container के अंदर server.js
27:27कहां पर setup होकर आए
27:28docker server.js
27:31delta folder के अंदर
27:32node app folder के अंदर available होगा
27:35तो वो folder structure जो है
27:37वो हमें यहां पर define करना पड़ेगा
27:38यहां पर तो हम simply server.js
27:40run कर देते हैं visual studio code में क्यूंकि हम
27:42node app के अंदर ही हैं पर जब हम
27:44container के अंदर इस command को run कर रहे हैं
27:46तो अभी हम अपनी home directory के अंदर हैं
27:49अभी हम इस node app
27:50folder के अंदर नहीं है तो इसलिए यहां पर
27:52अपने folder का हमें जो complete path है
27:54उसे define करना पड़ेगा to run
27:56our container. तो this is how
27:58we dockerize our application
28:00यह basically सारी हमने instructions
28:02लिख दी है to convert our node
28:04application to a docker image
28:06अब इस docker file को हमने create कर लिया है
28:08इसे run करने के लिए we basically
28:10run the docker build command
28:12जो हमारी application को run करेगी
28:13हम simply अपनी app का नाम
28:15define कर सकते हैं यह basically हमारी docker image
28:17का नाम होगा और हम चाहें तो साथ में
28:19कोई version भी define कर सकते हैं
28:21hyphen t stands for tag अगर हम
28:23अपनी image के साथ एक tag देना चाहते हैं
28:25और dot से हम अपनी file को select
28:27करते हैं तो यहां पर आ जाते हैं
28:29in the terminal हम basically docker
28:31build करेंगे docker build
28:33hyphen t हम अपनी app को
28:36नाम देंगे let's call it app
28:37one point या let's call it
28:39node app
28:41one point o उसका version हो गया
28:43and उसके बाद dot करके हम
28:45अपने files को select करेंगे
28:47अब क्यूंकि हम already node app folder के
28:49अंदर ही हैं तो automatically docker
28:51हमारे लिए is docker file को detect कर लेगा
28:53और हमारे लिए docker image को build कर देगा
28:55let us run this command and it
28:57has started the build process
28:59so our image has been successfully
29:01exported and let
29:03us clear this and अब अगर हम
29:05check करें for docker images
29:06तो हमारे पास एक new image आ गई है
29:09which is node app
29:11version 1.0 and
29:13हम चाहें तो अब इस image का भी
29:14docker container run कर सकते हैं
29:16तो if I do docker
29:18run अपनी image
29:21का नाम which is node app and
29:23उसका version 1.0
29:24let us run it
29:28and इस तरीके से
29:29हमारे पास आ गया
29:30server running on port 3030
29:32हमारी जो node.js की application थी
29:34वो docker image के अंदर convert हुई
29:35image से हमने container run किया
29:37और container के अंदर
29:39automatically हमारा जो server है
29:40वो स्टार्ट हो गया है
29:41अब जनरली organizations के अंदर
29:43when we dockerize our application
29:44तो उसके अंदर हमें
29:45as such अपनी जो docker file है
29:46या फिर mongo.yaml file
29:48इन्हें अपने image के अंदर
29:53बाकी सारी files and folders को
29:54separate folder के अंदर डाल सकते हैं
29:56और उस folder को हम अलग से dockerize कर सकते हैं
29:59by removing this file and this file
30:01हम चाहें तो अपनी node modules को भी
30:03remove कर सकते हैं
30:03अगर हम जब dockerize कर रहें अपनी application को
30:06तब हमने अगर node modules को include नहीं किया है
30:09तो उस case में हमें इहां पर
30:11traditional instruction लिखनी पड़ेगी
30:12which will be run
30:15npm install
30:16जिसका मतलब है कि अभी हमारे पास
30:18अभी जो container यहां तक setup हुआ होगा
30:20उसके अंदर अगर node modules नहीं है
30:22तो node modules को हमें पहले
30:24install करना पड़ेगा before we start our server
30:27तो यह instruction important हो जाएगी
30:29अगर node modules नहीं होते
30:30पर जब हमने dockerize किया था
30:31we have added the node modules, तो I hope कि
30:33यहां तक में clearly समझ में आया होगा कि किस तरीके
30:35से हम अपनी node JS application को dockerize
30:37कर सकते हैं, we can convert it into a docker image
30:39and then we can also run containers
30:41using the same image
30:47next we are going to learn about how to publish
30:49an existing docker image onto docker hub
30:51तो उसके लिए we are going to go on
30:53docker hub and we are going to create and
30:55sign up a new account, so this is
30:57the account that we have created, we can also
30:59visit our profile under the my profile
31:01option and यहां पर जाकर
31:03basically we have to go on to this
31:05repositories tab, जहां पर
31:07we will create a new repository
31:08this is going to be very similar to how we
31:11sign up on GitHub and how we create a new
31:13repo there, उसी तरीके से यहां
31:15पर हमें एक new repository create
31:16and we have to give it a name, we can give it any
31:19name, so let us give it a name of
31:21my node app, we can
31:23also give it a short description if we want
31:25and we are going to create a public repository
31:27so let us create this
31:29finally when it's done, we have
31:31created this repo for us
31:33अब हम अपने host system पर जो भी हमारी पास
31:35docker image है उसे यहां पर इस
31:37repository के अंदर पुश कर सकते हैं
31:39पुश करने से पहले we need to ensure that
31:41हमारी जो भी docker image है जिसे हम पुश कर रहे हैं
31:44उसका यही same name होना चाहिए
31:45although हमने यहां पर as such इसे
31:47कोई tag name नहीं दिया है, so the tag
31:49will by default be latest, but we have
31:51to create a new image on
31:53our local host machine with this same name
31:55तो इस name को एक बार copy कर ले रहे हैं
31:57and let us come here, हम अपनी same
31:59node application को दुबारा
32:01कनुगट करने वाले हैं into a docker image, but this
32:03time with a different name, तो उसके लिए
32:05we can write docker
32:07build hyphen t
32:09and this is the name that
32:11we actually want for our application
32:13dot and इस तरीके से we'll
32:15start building a brand new image
32:17जिसे हम finally push करेंगे docker hub पर
32:19तो finally हमारी image ready हो गई है
32:21we can also go and see the image
32:23on docker desktop and
32:25अब हम इस image को push करने वाले
32:27on to docker hub and push करने के लिए
32:29we need to use the docker push
32:31command, we need to do docker push and
32:33उसके बाद अपना image name, अब docker
32:35पर अपनी image को push करने से पहले we need to ensure
32:37हमने अपने terminal पर same username
32:39and password के साथ login किया है, जिसको
32:41हम docker hub के उपर use कर रहे हैं
32:44हमारे पास command होती है
32:45docker login, but since I am already logged in
32:48I need to log out first
32:49so docker logout से हम कभी भी अपनी
32:51terminal से logout कर सकते हैं
32:52तो this will lead to the removal of
32:55login credentials and उसके बाद
32:57we can do docker login
32:58अब login करने के लिए docker हमें
33:00two different options देता है
33:01first option is
33:02कि या तो हम इस command को
33:04use कर सकते हैं, जिससे हम
33:05username and password से sign in कर सकते हैं
33:07हमें वही same username and password
33:09use करना है, जिसे हमने
33:10docker hub पर use किया था
33:11and the second way is कि docker
33:12हमें एक special code देता है
33:14जिसे हम अपने उस browser पर
33:15इस link को खोल कर
33:17enter कर सकते हैं
33:18जहां पर हमने
33:30तो इस तरीके से
33:31we are now logged in in the terminal
33:33and finally the login was successful
33:35and we are logged in
33:37तो इसे clear कर लेते हैं
33:38and अब हम finally करेंगे docker push
33:40जो भी हमारी image का नाम था
33:42which was dev apna college
33:44this is basically the username
33:46and उसके बाद हमारी image का नाम
33:48because there is no tag
33:49हम उसे skip कर सकते हैं
33:50and directly हम करेंगे push
33:52तो the image will get pushed
33:54onto the repository
33:55and वो जो layer by layer
33:57pushing होती है
33:58वो start हो चुकी है
33:59and finally we have pushed the entire image
34:01onto docker hub
34:02हम चाहें तो यहां पर आकर refresh कर सकते हैं
34:05and refresh करने के बाद
34:07we can now see our image
34:09which has a tag of latest
34:11and हम चाहें तो tags में जाकर
34:13यहां पर check भी कर सकते हैं
34:15so this is our image size
34:16and कभी भी अगर इस same image को
34:18अब हम अपने system पर local system पर
34:21पुल करना चाहते हैं
34:22तो हम use कर सकते हैं इस command का
34:24basically the docker image that we built on our local system
34:27is now publicly available
34:28we can share this image or the repo link
34:30with other people who want to use the same application
34:32onto their system
34:33इस तरीके से हम docker hub पर अपनी custom images को
34:36push कर सकते हैं
34:36and फिर उसके बाद हमें local system पर
34:38as such अपनी application रखने की जरूरत नहीं है
34:40हम किसी भी time उस docker image को
34:42pull कर सकते हैं system पर
34:43and अपनी उस same node.js application को run कर सकते हैं
34:46inside a container
34:47you

Recommended