Docker Tutorials for Beginners | Narendra P | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

15 Lessons (2h 23m)
    • 1. 1. Introduction to Docker

      12:53
    • 2. 2. Docker Architecture

      3:42
    • 3. 3. Docker Components

      3:39
    • 4. 4. Installing Docker on Ubuntu Server using Bash Shell Script

      6:06
    • 5. 5. Creating our First Docker Container

      15:08
    • 6. 6. How to use Docker Image tags to create containers

      9:17
    • 7. 7. How to rename a container ?

      4:30
    • 8. 8. How to access the application which is running in Docker Container ?

      12:52
    • 9. 9. Creating Docker Image using Docker Container

      13:41
    • 10. 10. Introduction to Dockerfile to Create Custom Docker Images

      11:50
    • 11. 11. Basic Steps to Create Custom Docker Image with Name and Tags using Docker Build Command

      7:13
    • 12. 12. List of Dockerfile Instructions or Commands

      4:52
    • 13. 13. Our First Simple Dockerfile

      13:24
    • 14. 14. Dockerfile Creation to Launch Simple Python Flask Applications

      13:22
    • 15. 15. WORKDIR Instruction usage in Dockerfile

      11:00
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

66

Students

--

Projects

About This Class

Description

This Course is focused on concepts of Docker , It Covers the Concepts like:

                Introduction to Docker 

                Launching Docker Container

               Creating Docker Images from a Container and with Dockerfile

                Automating Docker Actions with REST APIs

Who this course is for:

  • This Course is designed for individuals looking for mastering Docker and Docker REST APIs

Requirements

  • Basic Knowledge about Linux is required
  • Basic Bash Shell and  Python Scripting Knowledge
  • AWS Account or Any Cloud or VMWare to launch Linux System for Docker Host.

What you'll learn

  • Basics of Docker
  • Docker Image Creating with Dockerfile
  • Automating Docker Tasks with REST APIs

Meet Your Teacher

Teacher Profile Image

Narendra P

Automation Engineer With Scripting’s and Tool’s

Teacher

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. 1. Introduction to Docker: Hi friends, welcome to Docker tutorials for beginners and decisions that ended up instructor for this course. First, let me go with introduction to Docker anyway before entering into Docker concert. First, let me tell you what is the story before Docker. Now to understand about this concept, I am taking a very simple example that is, just assume that we need to run one Java application. See whenever if you want to run any Java application, we need some database or were some application server and web server. So here in my case is simply I'm taking, we need one MySQL database server, one Tomcat application server, and one IIS web server. That's fine. And here, just assume that because of some compatibility issues with your operating system, we need only Windows Server to those untoward to run MySQL database server, and 2016 to run Tomcat applications or what? Anyway, it needs some Java. And then Windows Server 2019 to run IIS web server. Fine. So now we need three servers. One is Windows Server 20122016, and then 2019. That's fine. So here my question is how to get required servers. So actually we need three different operating systems or servers, right? So how to get them? Actually we hope to ways before Docker concept they are first one is get three computing the wedges with the required hardware. I mean, let say suppose I need each computer with 16 GB RAM and then to TB hard disk just to get three devices under then install with your required Windows server operating system so that we can create our three servers directly get your required server from any cloud, but is one way audible simply, we can create 3D virtual emissions from VMware. Now here, to get more clarity on Docker concept, simply, I'm going with second week. We are going to create virtual missions from VMware. And assume that your VMware is running on Windows Server. Fine. Now let me go with how to create VM missions or required servers from VMware. See whenever if you want to create any server from VMware. First of all, you need to run your VMware on any one of the server. So just assume that I am running my VMware or simply hypervisor on one of my Windows Server. And for this Windows Server, just assume that we have 128 GB RAM and hard disk. Fine. Now we have VMware. Using this VMware, we can create any number of settlements, but be clear that any number of solvers depends on this configuration information. Suppose e Here we have 128 GB RAM and ten dB hardness. Anyway, in our case, suppose we need three servers. Now, just assume that we are going to create each server with 16 GB RAM onto TB hard disk. So 16 into 348 GB, a 102 into 36 PB. Yes, we have more than that with your host operating system. So that way we can create three servers. Now just assume that we are going to create three servers. Anyway from VMware. Whenever if you want to create any server, we need one ISO image. That is nothing but your operating system image. And be clear, suppose I'm going to take waste image are suppose Windows Server 2012. So using that email, I can create my requires hard work for my database. And assume that second time I'm selecting my ways imaged as Windows Server 2016. Yes. From that we can create one Windows Server. Same way. I'm going to take different waves image that is Windows Server 2019. And by using that with image, I'm going to create one more server. Fine. So after creating your three servers using your VMware, now I'm deploying MySQL database server on your toes and tool server, then Tomcat server on Java on your to-do and 16 server, and then IAAS webserver on total. Fine. Now we'd done our required setup to run Java application. This is fine. But what is the drawback here? Very simple. C before telling that C actually as of no, on my laptop, Suppose I have Windows ten. Let me open start Minow on my Windows ten. Now if i how by default, different types of software with my Windows ten. But I am not using all these default software to run either database server or Tomcat server IIS web server. I don't need them to run any one of these application. So if you're not using them, why we need to install it with our operating system. See if more number of softwares with your ISO image, then it will take more time to launch your server. But if you how less softwares with your ISO image, then it will take less time to launch your server. So if you launch your server with the less time, then we are saving some time for our production. Right? So because of that here, what we will do is we will minimize our ISO images as much as possible. Fine. And one more thing, if you observe here we are using all servers, Windows servers, including your host operating system. Say actually, if you go with any operating system, we how to parts. They are carnal and softwares. See here, colonel is simply a program using that we can interact with the hardware. Now that can really sing, go with Windows Server 2012 or 16 or 19 or whatever it may be. Now, same colonel, across all your servers. Then why we need to install same candle on all your sorrows and shove that. I can use the canal which is there on your operating system so that, that canon software part also I can reduce in my ISO image, right? So if you reduce your iOS where you may size then will take very less than to launch your server. That is actually an advantage. Fine. Anyway, softwares are nothing but required libraries and packages 40 what server? That's fine. Now, our concept is. If you are able to reduce image, then it is an advantage. So that is the concept of your Docker. But how let me tell you that. Oh, let me go with create servers using Docker. See whenever if you want to create servers using VMware, actually we are running somebody where VMware. Same way whenever if you want to create service using Docker, we need to run your Docker somewhere. So let's say I'm running my Docker on Windows Server. Fine. Now, here, using Docker, we can create our servers. But here we have a small difference between Docker and VMware with respect to operating system or host operating system. That is, if you're host operating system is Windows server, then using Docker, we can create only Windows servers. So like Windows Server 2012 or 16 or 19. Only Windows servers we can create using docker if you're a host operating system, Windows. Suppose these host operating system, let's say Linux. Then using Docker, we can create Linux operating systems, let's say open to our HDL sent ways. So say Linux, something like that. Fine. But if you go with the VMware respect to of your host operating system. Using VMware, we can create any type of operating system, any type of server. Fine C, to create your servers using VMware. We are taking ISO image. So here also to create your required servers using Docker, we had to take ISO image. But here that ISO image is minimized ISO image nothing but it consists of only a required software's. Nothing but libraries and packages to run your application, let's say. And here that minimize the ISO image is called Docker image weekly or don't get confused. See if you want to create a server using VMware, we are taking an operating system IS where you made. So here also using docker, if you want to create a server, we need one ISP amazed, that is nothing but Docker image. But we have a difference between your normal operating system IS well, you mentioned and Docker image that is either operating system, ISO is complete one, but Docker image is not a complete ISO image. It is not having kernel and also additional software. It will only required libraries and packages to run your particular application. That's fine. Now, using this Docker image, with the help of Docker, we can create any number of servers. Of course that n number of servers depends on the configuration of your host operating system. Fine. Now assume that we need to create three servers. And one more thing you are running now your Docker on windows server. That's why using Docker, you can create only Windows servers. Fine. Now assume that I want to create Windows Server 2012. So if you want to create your particular server with Watson, you have to sell it to proper Docker image. We have n number of images already available with the Docker. So we will select the required image based on our required server. Now assume that I selected are darker remains for Windows Server 2012. So now by using that image with the help of Docker, we launch in one server. So now the server is not a complete one. That's why it's simply I am calling it as mini Windows server. That is what, 2002. Well, anyway we need two more. Now assume that I selected Docker image for 2016. So from that, with the help of dagger, I created many windows server 2016, same way, mini Windows Server 2019. Fine. Now we have our three servers. Fine. No, let me deploy our required database server, Tomcat server on Java, on ASR, we're on our servers. Fine. So be clear. Our servers, whatever the servers we created with the help of Docker, by taking Docker image, they are not complete one, they need camel. Now these three servers will use carbonyl from your host operating system with the help of Docker. Fine. Now instead of calling these three servers as Mini servers, simply we are calling them as containers Nazi. And here one more thing. Suppose I want to create Linux servers. So in that case first the thing, you how to take your host operating system as the Linux server. It may be open to or ritual or CentOS, whatever it may be. So using that Linux host operating system with the help of darker, by selecting required Linux image, it may be open to image for auditorially maize or CentOS image, we can create your Linux servers. Fine. So this is just a very basic idea about your Docker. Oh, this idea, let me go with what is a docker? Simply, Docker is this software to create a mini server, but don't tell that it is used to create a mini server. Instead of that, Docker is a software to create a container. So how we are creating a containers using Docker with the help of image, Docker image. So finally, we can create n number of containers on a host operating system. On all containers are virtually separated. So while running your containers with the help of Docker, all containers, we'll assume that they're running on separate operating system. Fine. And finally, simply, Docker is a containerization tool because we are creating containers using Docker. Fine. Now, if you search in Google, what is a Docker? You will get different definitions, right? But as of now, I don't want to go with them. So well, going forward, step-by-step, I will add concepts to your Docker so that I will make complete definition for what Docker, so that it is very easy as a beginner. Okay. Okay guys, thank you for watching this video. 2. 2. Docker Architecture: Prince here or concept is Docker architecture, says simply this is Docker architecture. But let me go with our known concept that is creating containers using Docker. See whenever if you want to create a container using Docker, first of all, you had to install your Docker on any one of the operating system. So after installing your Docker on anyone of the operating system, based on the type of container. We will select a Docker image. Then from the Docker image, with the help of Docker, we'll create our containers. We RDD hybrid discussion on these, fine. Now if you observe clearly in this diagram itself, we have our Docker architecture. Now let me extract that step-by-step. Now, here, if you observe the very first took part in this entire diagram is you were infrastructure. Now assume that this is our infrastructure with some RAM hard days and some CPU's fine on top of your infrastructure simply we are installing, suppose here Windows server, not only Windows server, we can also go with open to a Linux or our HCl or CentOS, whatever it may be. Now assume that on top of this infrastructure, suppose I installed some x-ray did operating system. Now this is called simply your host audio server. Now onwards host or on your server, we are installing Docker. Now assume that I installed Docker. Anyway, that is called simply Docker Daemon or Docker Engine. Fine. Now, once if your Docker, using Docker, we can create containers by selecting required Docker image. Fine. Now one more thing. See, this Dockery is simply a service or engine. So with the help of this Docker Engine or service, we are going to create containers. That means we need to pass some instructions to this Docker daemon. So how we can pass, we need some interface between us and docker engine. Now for that, we are using a simple software called Docker CLE. That's it. Now using this Docker CE and Lee will pass instructions to your Docker Daemon or Docker engine so that that will create our start or stop or destroy your containers. That's it. Fine. And here, this Docker CLI, you can install on the host to where you are running your Docker Engine or else you can take one separate host there. We can install your Docker CLI from the remote server. Also, you can interact with this Docker Engine. Or we can also communicate with your Docker Engine from remote location using rest APIs. So how to do that? We will see now, That's fine. Now here, if you observe we are creating containers by taking Docker images with the help of Docker engine. Now assume that I need to create three types of containers, let say Windows Server 2012 container to those, and 16 container and 2019 container. That means here you need three types of Docker images. So from where you will get those images, you no need to worry for that already. Docker is maintaining some images in Docker history. So how to get them we will see in our course. So be clear, Docker images are already available with the Docker registry. So whenever if you want to create your required container simply we will get our Docker image from Docker history and we'll create our container. Fine. Suppose I want to customize that Dockery, MS. Yes, we can customize and weekend store images in your Docker history. Alleles. We can maintain our customer base three. Then we can store our docker images. Fine. Now, this is simply Docker architecture. Okay? Okay guys, thank you for watching this video. 3. 3. Docker Components: Sr or concept is Docker components. See Docker components are nothing but components which we have in our architecture diagram. Actually we already know them. They are like, let me list one by one. Docker host, Docker Engine, Docker, Client, Docker objects like images, Containers, Networks, volumes, and plugins. And finally, Docker registry. See here, Dakota hosts is nothing but on which observer you are going to run your Docker engine. That is nothing but your Docker host. So in our architecture diagram, suppose here x-ray good operating system is nothing but our docker host, Docker Engine. So using Docker engine only, we are going to create containers simply, Docker Engine is the your required software. Fine. Then Docker Client C Here we have two types of claims, Docker CLIA or rest EPA's. So using these two, either Docker CLIA or rest APIs, we can communicate with your Docker engine so that we can start containers or we can stop containers. We can deploy containers, we can remove containers. All those actions we can perform with the help of Docker clients find, then Docker objects. So as of no, we know only images on containers, but don't worry about remaining objects. We'll discuss them later. Fine. Anyway, what is image see generally in our image is nothing but an operating system, ISO image. But here Docker image is an image only. But it does not include colonel software or any unnecessary softwares. Instead of that, it has only required libraries and packages to run your particular application. Fine. So simply, in our Docker TMS, Docker image is a template to create a container. That's it. Fine. The next one, container C, using your Docker image, we are creating our container. Generally we can say that container is a Mini server or mini system. But instead of calling Mini server or mini system in terms of Docker terminology, we are calling that as a container. So finally, we can say that the running status of your image, because we are creating containers with the help of Docker image only. That's why the Running status of your Docker images in nothing but container. Right? Fine. Then finally, Docker history. See Docker racer is nothing but a place where we are going to store your Docker images are a place from which you are going to get your required Docker images. So initially, we will go with official Docker raised three. That is how it dot dot dot.com. Let me show you that. So you simply, if you search hub dot dot, dot.com, it will go to official Docker raised to replace. That is called simply Docker Hub. Now let me open that. This is Docker Hub. Now here, if you simply click on Explore, Here we have explored. If you click on that, it will display available images. See that there are a lot of images. On the bottom. You how pages see that? 1234, right? So these all are available images from your Docker Hub. So initially we will take our required image from Docker Hub. Only later we can customize that image so that we can create our custom image. Fine. That's it. Okay. Okay guys, thank you for watching this video. 4. 4. Installing Docker on Ubuntu Server using Bash Shell Script: Print sheared or concept is how to install Docker on Ubuntu server. So here we are installing Docker on Ubuntu server using Bash shell script anyway before that, if you remember, this is our Docker architecture. So if you observe here, we are installing Docker on top of some host. That host may be with Windows operating system or with any Linux operating system. So again, in Linux operating system, We can go with either open to or CentOS or Rachel, or Amazon Linux or IBM Linux. It could be any operating system. Fine. Now first let me get my open to server C here. I'm taking open to server from AWS cloud. Now, I already created the server. Let me login into it. So simply, I'm logging into our urban to server. Now. Just let me verify what is the operating system to that open to anybody. This is the latest one. That's fine. Now, we how our required operating system. Next thing is when it installed Docker, not to install your Docker. We hope to go and get Docker software. Anyway before going to that, actually docker comes in two editions. One is Docker Community Edition, and the second one is Docker Enterprise Edition. There are some differences between these two additions. Anyway, simply, Docker Community Edition is like open source. You can download and install with your required operating system. And this Docker Community Edition purposes just to get practice with your Docker container ation concept. That's it. And here, Docker Enterprise Edition, definitely, it has some advanced concepts compared to your Docker Community Edition, because this is Enterprise Edition. Again, Docker Enterprise edition is available in terms of basic standard and at once, additions. Simply are given some differences between your community edition with your Docker Enterprise Edition. So initially we will practice with Docker Community Edition. Anyway, Docker Enterprise Edition is also available as trial version. So later we will use that and we'll use some advanced concepts from our Docker Enterprise edition as well. Fine. Now let me go and install Docker Community Edition on our open to server. Now here we are installing through Bash shell script. Now you can get your required bash escape in this location. Now let me open my repository, GitHub repository. So just open Docker tutorials for beginners. Clone this repository to your local host. I mean, where you want to install your Docker. So this is the server. So what I am doing is simply, I'm cloning it. So anybody is open but opposed to read vertically, you can clone it. Git clone that URL. Fine. Now here we have the repo. So enter into it. Now here we have our first introduction concept. So go to that. And here we have a shell script. Now see here we have shell script. So nothing is there. Whatever the steps are manually we are performing to install Docker. All those steps I added in this script. So if you open and if you go with one by one, you will come to know what are the steps, very simple steps. Anyway. First, let me try to forward the execution permission for it. Now I am running it. Say that please run this script from root only C to install your packages, you should have root privileges or you should run your commands from root user. So anyway here I designed descrip such that it has to execute only from root user. Now let me switch into root. You can copy your required script into your root location or directly can provide complete path. So let say home. Under this user, we how Docker tutorials in that introduction part, we have a shell script. Now let me run it. See that oases I interpret as open to then DES installing. So whatever the steps we are performing manually, all those tips I added in this city. So it is going to install your required Docker Community Edition anyway, it will do, it will install latest Docker on your host. So just wait. So before executing the script, just to open it and see step by step, what is the logic is there inside that? Fine. Now it is almost hidden. And one more thing, this script will work only on open to server. Yeah, fine. Now Docker has been installed successfully on this host and it is up and running. You can verify it using system CTL status Docker. Docker is up and running. Now, after that you just verify some commands. Let's say docker space hyphen, hyphen version. We'll use docker Watson, anybody who has the latest version as of now, then Docker version, see that how you are going to get, you're getting some information about your plane, turn your Docker Engine in within his community version. Fine. And one more thing, you can also run docker info. So just us off no, just update this log. You don't need to worry about this anti log information going forward based on our known concept, I will explain about this step-by-step. Fine. Okay guys, this is the simple way just to install your Docker on open to server using Bash shell script. Okay? Okay guys, thank you for watching this video. 5. 5. Creating our First Docker Container: Friends here, our concepts or creating our foster Docker container and basic commands of Docker. Saying before entering into our concepts, First, let me log in into our docker host. See Docker host is nothing but when we installed our docker, if you remember, we install Docker on our open to server in our previous video? Yes, Docker, is there? No. Let me verify once our ways open to server. Fine. Now let me switch into root. Initially, I will work with the docker from root user. Later we will see how to work with Bucher from different users find. And one more thing, let me verify the status of Docker simply by using systems CDL status Docker. Docker is up and running. Now let me verify the darker version. Simply docker space iPhone, iPhone version. It will do only your Docker version. If you want to see client as well as your Docker server information simply you can then Docker version. And you are also having one more command called Docker info to get more information about your Docker. Fine. Now we are ready with our Docker. No, let me enter into our concept that is creating our foster Docker container. C. If you want to create a container using Docker, unique Docker image. Suppose if you want to create a container with CentOS operating system, then you need doc remains for s2 is suppose if you want to create a container with open to operating system, then you need Docker image with open to operating system. Fine. But from where we will get this Docker images. See Docker images can be good from Docker registry or simply from Docker Hub. Anyway, before going into that, let me show you some basic commands, S0. These are the, some of the basic commands. We will explain them one by 1. First thing, Docker images. That is simply a command just to know that what are the images are available with your Docker host. Docker host is nothing but where we install our Docker C, this is our docker host. Let me verify with Docker images. So as of now with my Docker host, I don't have any Docker image. Right? Then how we can get it c before getting it. First, let me open our Docker registry or hub dot docker.com. That is the official website of Docker to find the available images with Docker? No, let me open that. So once it is open, simply click on here, explore. There is explored option. Click on that. Now here we have some such bar. Let me such with the CentOS simply type sin2 is and then Enter. You will get lot of images with respect to send to AC maze. But don't worry, we'll discuss them step-by-step as of now. After that, yes, there is a central image with your Docker Hub. Suppose I need open to humans, simply type urban to under then enter. Yes, there are number of open two images, fine. See internal searching your required image from Docker Hub, such option that Italy from our command line itself. By using this command, we can such required image from Docker Hub. By default, our Docker is configured with the docker hub. So whatever you are searching from command line, that such information is from hub dot docker.com. Fine. Now let me set simply Docker. Such. Let's say sent away is just enter this many number of images. Centos images are available with your Docker Hub or else. Let me search for Open to. Now see that this menu open to images or available with your Docker Hub. Fine. So now we can able to such our required image in your Docker Hub. But how to download that with our local host or without Docker host. Very simple. We have a command for that, that is simply docker. Pull your required imagining. So suppose here. First, let me run docker images. So as of now, we don't have any images with our local host or without Docker host. Now what I'm doing is simply Docker sent ways. No, it will download sent ways image to our local host or to our docker host. Now, it has been downloaded. Now verify by running docker images. Yes, now we have CentOS image with our local host or without Docker host. Fine. Now let me pull open too as well. See that it is downloading. You are open to amaze. You had to wait for some time. It will download. Yes, it has been done. Let me verify it. Available images on your local host or with the word docker host? Yes. Now we have two images with our docker host. Fine. Now, once if you download your images in case if you want to remove any one of the image or all images you can remove by taking Docker RMA, remove image with respect to image ID. See that if you run docker images, it is giving some repos. That is, you are open to or CentOS image name then tax as of no, don't worry about tags. We will see in detail ago tags. There is image ID and it, when it was created size. Suppose I want to remove CentOS image with my Docker host. Yes, we can remove it. See simply docker. Remove image, then image ID, enter. It has been removed on your Docker host. Docker images. See that we have only open too, because just now we removed our CentOS image on our docker host. No, let me pull it docker, pull sent waves. It is downloading. So once it is downloaded, if you rerun your Docker images, it will list Oliver available images with your Docker host. Anyway, we have two images. That's fine. Then what is the next command? Docker ps. C docker ps simply will list the running containers anyway as AF No, we did not created even a single container. But let me verify. Docker ps, there are no running containers. And we have one more option with the ps that is hyphen yea or hyphen, hyphen all. It will list the running and stopped the containers. Let me run it once again. Docker ps, iPhone, yay. Iphone, iPhone all. So we don't have any running containers or stopped containers as of no width our docker host, fine. Now, let me go with how to create a container. C. If you want to create a container, we how to use docker run command. But for docker run command, we have number of options for time being. Just remember this command going forward will discuss in detail about this command. Now simply, if you want to create a container, you how to use command as docker run hyphen, hyphen D, then you are required imagining. See that? Docker hyphen, hyphen D. Suppose I want to create CentOS images simply run s2 is the trip. So your container has been created. So how to list containers simply using docker ps c that we just know we created one container with respect to CentOS image. That's what it is giving. C whenever if you run docker run hyphen IT hyphen D sent away is then automatically it will create a container with the operating system as CentOS. And one more thing. Whenever container is created by default, your Docker, We'll do one ID for that. That is nothing but Docker container ID. Now, see, this is the container which we created just now. And this container is created with respect to CentOS image. And seven seconds ago, let me verify it once again. About a minute ago we created this container, right? What is the status? It is up. And as of now we are not giving any ports. Don't worry about this. And observe here names. See by default you are docker will use some name for your container, but you can also modify that. We will see that later. Fine. So as of now we have only one container with our Docker. Now, let me create one more container by taking images as open to. So simply Docker, run hyphen, hyphen D. Simply, you are imagining open to see that container has been created. Now let me list all the running containers simply by taking docker ps c that we have two containers. Now, this container is created by taking images as open to or simply with open to operating system. And this container is created by taking images are sent waves or operating system has sent away as fine. And see that whenever if you create a container, Dockery is giving some container ID, along with that by default is giving some names. So be clear, going forward, we can change that name. That's fine. Now, let me go with the remaining commands. S0, we created a container. Now, I want to access that container. I want to enter into the container, yes, you can enter by using this command, simply Docker, execute e FCC, hyphen IT container ID. Then with respect to some shell, suppose I want to use SSH shell or bash shell. So based on that shell, you can access that container. C, that simply Docker EX EEC, hyphen IT, take anyone of the container ID. Then I want to login. I want to access this container. I want to enter into that container using, let's say Bash shell. So that now you are in this container. Fine. If you want to verify what type of operating system is there with that container, simply run cat slash EDC ways released CentOS Linux, let's say, fine. Now let me come out from the container C, if you want to come out from the container unit to press Control, and then immediately press P and Q so that you will come out from your container. Fine. Now let me enter into open to image. So simply again, Docker 0x e, c, hyphen IT, then Container ID. Let's say I want to enter into this container using SHE shell. You can also use Bash. No problem. No. Let me verify operating system for this container cat slash EDC ways release. Yes, open two. Now, if you want to come out from this container, simply control immediately P and then Q. That's a fine. Now see that docker ps we have two containers. No, let me stop one of the container. It may be any container. Suppose I am taking this container. So if you want to stop your container, simply Docker, stop container ID. That's it. Now if I run docker ps c that D showing only one container which is running. Just know we stopped open to container. Now, if you want to list the running as well as Stop the containers, then you have to run command called docker ps with option called hyphen yea, our iPhone, iPhone all see that? Now this is exited, which is not running. Anyway, to list running as well as top to containers, you have to take docker, ps, hyphen yea, or iPhone, iPhone all command. Fine. Now let me start this container. Yes, we can start it simply by taking the Docker start container ID. Now that container has been started, if you want to verify simply docker ps. Yes. Now both the contains a running fine. Now, suppose I want to delete any one of the container or all containers. Let me remove this container. If you want to remove the container, command is docker. Remove your container ID. But if I run that you will get an exception C that you can't remove a running container. So if you want to remove a container using Docker RM command, you how to stop it and then you have to remove it. Audience forcefully also, you can remove that container simply by taking remove hyphen F, c. Now let me display docker ps, or docker ps, iPhone yay or iPhone, iPhone. All we have only one container. It has been removed. Which one? Yeah, this one. It has been removed. Not stop, but it has been removed. There is no container now. Fine. Now we have only one container called CentOS container find. Now, instead of using hyphen EF option, if you want to remove a container, what we have to do is first we need to stop the container. Now let me stop this container first. Now. See docker ps. There are no running containers but Docker PSI, funny, a stopped container. Is there not to remove, stop the container directly. You can take command called docker. Remove your container ID, that's it. Now there are no more containers running or stopped. Fine. Now I want to create a container. Yes, you can create it. Docker. Run hyphen, hyphen D, Let's say CentOS container has been created. See that? It is running. Let me run only docker ps. Let's wait. So if you want to enter into this container, again, what is the command? Docker EX EC, hyphen IT, then it may be shell or bash shell. You can take initial. Fine. Now if you want to come out from the container, simply press Control and then immediately P and Q on your keyboard. Let's say. Okay, so guys, these are the basic required commands to work with your Docker. Okay, guys, thank you for watching this video. 6. 6. How to use Docker Image tags to create containers: Prince here, our concept is how to use Docker, amaze your tags while pulling images, or simply how to download required Docker image Washington. Now, let me go with our docker host. If you remember, we already pulled or downloaded to Docker images. Let me display them by using docker images. Now, see the output. We are having two images. One is open to, one is sent waves. And if you observe this output here we have a tag as well. Now these are tag is like Latest for your both images. What is mean by elitist? So simply latest is nothing but latest available image anywhere. Docker hub for your image. Now, if you remember, we already created two containers by using these two images. Now these two are the container's. No, let me enter into any one of the container. Let's say open to container, simply Docker, EXE c, hyphen IT, then you are contained an ID, then Bash shell. So here I'm using Bash shell to enter into your container. Now we are inside of our container. Now let me display the waste information of this container C that 20. So as of now, for Open to server, this is the latest version. That is the meaning of Latest here. Suppose now I need a container with open to waste worship as edu.duke before then how we can create it. Now first, let me come out from this container simply by pressing control p, q. Fine. So as of now our images or open to and CentOS, Now I need a weapon to image with 18 dot-dot-dot O4 waste wash and see that how I'm going to do it. Docker pull open to see simply if you run docker, pull open to, it will download the latest version, but I need particular version so that you had to pass as a tag. So here tag is nothing but simply a Techstar worship. Now see that colon 1804. Actually we how it indoors for version for our open to operating system. That's why I'm giving that as a tag here. Be clear while giving peg to pass colon here. Now let me enter, see that it is downloading 18 dot-dot-dot O4 open to Watson. Now, let me list our images which are there without Docker host. Previously, we were having only two. Now we are having three images. So open to latest on also open to four. Now let me create a container using open to 18 dot-dot-dot for how to create it. See basically, if you want to create a container, we have a command like docker, run hyphen, hyphen D, then image name. Now here you fight, you simply open to, it will create a container with the latest open to humans. But I need with this attack, then you were. Image colon you were tagged cutting. Now let me enter. Now it has been created a container with open to 18 dot-dot-dot for. Now, let me display the running containers. Previously we were having only two, now we have three. See, this is the latest container which we created. And see that image has been used by open to know, let me enter into this container. Now to enter into that container, simply command is Docker EX DC, hyphen IT your container ID, then which type of shell you wanna use. Suppose I want to use Bash shell to connect with that. Yes. Now we enter into container. Now let me see. Where is information. Now it is 18 dot-dot-dot for fine. Now let me come out from this container by pressing control pq. Now be clear, we how these three images and containers. Fine. And one more thing you have to remember that using only one image, we can create n number of containers. Whenever if you create a container automatically darker, we'll do some container ID to separate your container uniquely. And anyway, it is also going to give some random name. That's fine. Now, one more thing. Suppose here we are using CentOS latest version. Now what is that version? Let me verify it by entering into this container because this container has been created by your latest CentOS image. Now let me enter into Docker EX EC hyphen IT this container with the bash shell. Sorry, what happened? Sorry, we need to provide a container ID. So docker EX EC hyphen IT container ID bash. Now see your ways information. It is sent to waste a, suppose I need send two ways with the, let say six version. Now just come out from your container. Now let me pull. Let's say sent weighs six dot. If it is there, it will do. If it is not there, you will get some exception. See that CentOS six dots is not fun. Let me try with six dot. It is there. But now let me download it. Fine. Now let me verify Docker images. See that open to image with the tag as latest and open to image with the tag as 1804. Waves with the tag has the latest one and sent away is with the tag as 6.8. Now if you want to create a container using CentOS six 0.8c, Yes, we can create it. And one more thing, actually, to create a container, you no need to download or pull your image. If you're directly run docker, run command to create your container with your required image. If the image is there on your Docker host, it will use that otherwise automatically it will download read we pulled from your Docker Hub. I will do one thing. Let me remove Docker. One image. Let's say this image idea I'm removing. Now. As of now, if you observe your images or three, now I'm creating a container docker. Run iphone IT hyphen D. Send two ways with the six dot h. Now if I enter, it will create a container within this image anyway as off node that images not there with your Docker host, no problem. If it is there, it will use that image. If it is not there. Docker command will automatically download that from our docker hub, hub dot dot, dot.com. Now let me enter, see that it is downloading, unable to find the image locally. That's why it is pulling your image from your remote server. After pulling it is creating that container. Now see that Docker images. Just know your docker run command created a container using CentOS six dot-dot-dot. So while creating that it, it downloaded, it pulled, you are sent waves 6.25x1. You are getting here CentOS six dot eight, fine. Now let me list containers. Docker bs c here. Yeah, this one is the latest container which has been created by using CentOS six dot. That's you know, if you want to verify simply Dockery, FCC iphone IT, they were Container ID, then use Bash shell to connect with that. Now, we are inside of our newly created a container. No, let me verify the ways information. So this is six dot eight. I'm not sure whether we have waves released file or not. Instead of that, let say, yeah, Red Hat release. Now using this way, you can verify it. That's it. Okay. Okay, now let me come out from your container. That's great. So friends, simply remember that Docker image tags are useful to you. Required image from your hub dot dot, dot.com. If you don't mention any tag by default, it will pull or download the latest image. If you mention the tag, it will download your required image. That's it. Anyway, we will also create our required a docker images at the time also will create our custom tags. We will see that. Okay. Okay guys, thank you for watching this video. 7. 7. How to rename a container ?: Friends here or concepts or how Docker identifies a container and how to name or rename Docker containers. Now let me go with that. See by default, Docker uses three ways to identify any container. They are using UUID, long shot, and name. So here you UID means universally unique ID. Let me show you them on our command line C, this is our docker host. Now already we are running with some containers. These are the running containers on my Docker host. Now if you update this output for every container, you how one container ID. This is nothing but actually UUID short ID. And anyway, for this container already we have some name. Now let me show you UUID long. Say if you want to see the UUID long, we have a command called docker inspect. We will see in detail about inspect command later. As of now, just let me go with that docker. Inspect. You can provide your container ID. That is nothing but UUID is short. Just enter. Now see that very first, you will get your UUID long. Let me scroll up. This is UUID long. And here if you observe in this part is your UUID shot, see that this part is nothing but your container ID. That is you UID shot. And one more thing, you are docker will use either container ID, that is nothing but UUID short or UUID longer AD, or even a name of your container to work with your containers. Now see, what I am doing is docker inspect. Instead of giving container ID, I can also provide name of your container C that it is giving same output. That means Docker is using any one of these three names to identify your containers. That's fine. Now, let me go with how to provide a custom name to a container C. Whenever if you create a container using docker run command, it will create a container by giving some random name to your container. Now let me create one container by using docker run hyphen, hyphen D. Then let's say I want to create sent weighs six dot A2 or Shen. Now see that while creating this container, it is giving UUID long. That's fine. Now in days, actually the first two characters are nothing but your container ID. Now let me do one thing, docker ps c, that up to this. That is what container ID. Anyway, whenever if you create a container for your container, automatically, you are going to get one container ID on also are going to get some name. Not this name is random name, but I want to do my custom name to that. Yes, we can provide, no, let me create one more container by taking same image. But now I am giving custom name with option as hyphen, hyphen name. Let's say we are using this container to run some headshot application. Now I'm taking head char app container. That's, you know, let me run. Now, let me run docker ps c that this is the container just no weekly at it. And now further, we have given our custom name. So this is the way how we can provide a custom name to a container. We can also rename of an existing container and see how we can do it. Very simple using Docker rename, you were adjusting container name with a new name. Let me do that for one of the container. Suppose I'm using this container, simply docker, rename your old name. I mean existing name of your container. Then new name. Let's say this container I will use just to run some for employee salaries. Just assume they're not treat. Now let me run docker ps c that previously we were having different name. Now we have given our custom name, we renamed existing container name. That's it. Okay guys, thank you for watching this video. 8. 8. How to access the application which is running in Docker Container ?: Prince here or concept tease, how to access the application which is running inside of a container. Now let me go with that. See basically we are using containers to run applications, more specifically, microservices. Very soon we will discuss about microservices. Fine. Now here, let me run a static application using HTTP web server in a container. First, let me open my Docker host C here we already pulled some are docker images. These all are docker images which are available on our docker host locally. And let me display the containers which are running on my Dakota host. Now let me create a new container by selecting sent waves image with the six dot-dot-dot version. We already know how to create a container that is by using docker, run hyphen, hyphen D. Now let me take a name for my container, custom name, let's say static application. And here I want to create this container by taking sent ways image with Watson as sub 06 dot-dot-dot. Fine. See here one more thing, internal off and giving your image name. You can also provide image ID, either image name with a tag or simply can provide image ID to create a container with your required image. That's fine. Now let me enter. Now it has been created a container. Now let me list to the available containers. So this is the container which we created just no. Fine. No, let me enter into that container by using Docker EX EC hyphen IT, then Container ID. Then I want to connect with that container using Bash shell. Now I entered into that container. Now here, as of now, I don't have any HTTP web server. Now let me install it by taking yum install HTTPD command will install your head to the DPT website just to wait for some time. It has been installed your page 3D beauty web server on this host? No, let me verify the status. As of now. This with ease. Sent weighs 6.8. So Incentive A6 dot-dot-dot. You don't have system CTL command. Instead of that, you had to take Service Command, Service HTTPD status. So that head to the DPT is not running. No, let me start it first. So RVs HTTPD Start. Now let me verify this status. I'll see here your head to the debris services running fine. Now actually, I want to run a static website using this heterogeneity webserver. Now let me take a content for my starting website as this one. Now if you want to, so any static website using HTTP web server, you need to place index.html under dislocation. Now let me navigate into that location. Slash var. Wow, HTML. No, here we need to create index.html. Let me create that. Now let me paste our static content. Let me say we now, our static content has been updated in this location. Fine. Now let me access that index.html using curl command simply by taking you are hedged http, localhost, colon 80. Now by default you were HTTP web server will run on 80 port number. So simply, I'm executing this URL. See that you are getting your content which is there in your index.html. That's fine. If you observe, as of now, we are inside of a container. Now, I want to access this URL from outside of your container. Now let me come out from your container. Now we're outside of a container, are simply on our docker host. Now, how I can access the URL which is working inside of your container. Suppose if I tried to run curl this URL, see that connection refused because on our docker host we are not running HTTPD server. We're running history deputy web server inside of a container. Now, how we can access that head today, deputy web server from your Docker host. So for that, you need to map your Docker host port number with the word container port. Actually, if you remember wildly creating our container, we did not map any port of your Docker host with your Docker container. Now, our intention is we are running head to redeploy the web server on port number 80 inside of a container. That's why before creating your container unit to map the port number 80 with your Docker host to port number. You can take any port on your Docker host. And that podia to map with your head to the d pd web server port, which is running inside of your container. Now, first let me remove your existing container. So simply by taking Docker, docker, remove running container. So you have to take hyphen F forcefully. I am removing this container. Fine. So be clear. Whenever, if you want to access the application which is running inside of a container, you need to map your Docker host to port number with the word container port number. So container port number is nothing but on which you put your application is running. Now for that, nothing is, they're very simple. Already. We know docker run command to create a container. In that command itself, we have to add one more option that is hyphen p port number. Now here I am taking just to avoid confusion, 80 on my Docker host. Map with 80 on my container. Be clear. These first two parties on our docker host second port is on our Docker container. If you wanted to get more clarity, let me take here ADHD. So what I want the Portuguese there on my Docker host that is 8080. I am mapping that port with the API of my container. Now let me run it. Now. Let me run docker ps command. Now see that in your container information. Ports, this is your Docker host. Docker host to port number is mapper width 80 of your container port. Now let me log in into your container. Docker EXE c hyphen IT. Bashful. Now first, this is new container which we created just No, let me install once again this HTTPD by using m install HTTPD. So meanwhile, let me copy the our index.html. Now you had to wait for some time. It is almost are done. Fine. Now, let me navigate into Var www slash HTML. So here let me create an index.html file. Inside that, we have to paste our static website content. Fine. Now, we created index.html. First, let me verify whether you are HTTP web server is serving your static website from your container itself. So inside of your container, you can run in this way. I mean, CAL, HTTP, localhost, colon 80. See that? Ok, you are hated. Httpd web server is not running. Let me verify service HTTPD status. Now let me start it. Okay, now let me verify this status. Nobody is running. Now it is ready to serve you as static website. Now let me verify using curl command. That's it. And one more thing. Generally, if you run hostname command on your servers, it will do the host name the same way inside of your container. If you run host name, it will do the host name of your container simply your container read-only. Fine. Now, axis iva static website through your HTTP web server by taking HTTP colon slash slash local host audio or container ID inside of your container. Now let me come out from your container weekly. Now, let me run docker ps c, whatever the application is running with the port number 80 inside of your container. Now that application port is mapped with the 8080 on your Docker host. That's why you know, if you run a curl command from your Docker host to access your application, you have to take h 0 h report. Now let me run Carl hedge vdp localhost, or it can also take this IP colon 8080. Now see the result you are getting. Now actually this application is running inside of your container, but we exposed that portrait to your container. We map that to port 80, to port off our docker host. That's why we can able to access that URL from your Docker host. Fine. Now, I want to access this URL. I want to access this URL from my browser. So how we can access it. Now if you want to access from your browser, you need to get the public IP or IP of your server. Now here I'm using EC2 instance to run my Docker, Docker host. I'm running on my EC2 instance. For this EC2 instance, this is the public IP. Just take these public IP based it, colon 8080. And now let me add here HTTP slash slash C. Yes, we are able to access that application from our browser. So be clear, even though if you run your application inside of a container, you need to map the application port number with your Docker host. Because from external world, if you want to access your application, you how to access your application always with respect to your Docker host only. That's why we are mapping Dakota hosts to port number with your container application port number. That's it. So that is the concept of how to access the application which is running inside of a container. So be clear, we can access the application which is running inside of a container using port mapping. So that port mapping with the what Docker host. So simply, by using this command, we can map your Docker host to port with your content and applications port. So be clear, you can always access your application or micro surveys from outside, from external world with respect to your Docker host only. That's why we are mapping our docker host port number with your container application port number, let's say, okay. Okay, I thank you for watching this video. 9. 9. Creating Docker Image using Docker Container : Friends here our concert is why we need to build a custom Docker image C. Before understanding about this concept, first, let me give a simple setup that is simply deploying Jenkins application on Tomcat application server using Docker CentOS container. Now, for this setup, we need some requirements. The very first one is sent to a container and wake creating CentOS container, we need to map Docker container port with the docker host. See if you have any doubts on why we need to map Docker container port with the docker host. Please follow my previous video. Then. Next one is we need to install Java with container because we are running Jenkins application on Tomcat application server. And in that case, Tomcat application server needs Java. That's why we need to install Java with container, then install Tomcat with container. Then we need to download the Yankees dot var file and we have to copy that to Tomcat or web apps folder so that Tomcat, we'll run our jenkins application. And finally, we can access Jenkins application using the URL. We will see that at the end of the setup. Now let me go and create CentOS container C. If you remember, we already pulled some images without Docker host and also we are running with some containers. Fine. Now let me go and create a new container. So how to create a container simply by running a command called Docker run hyphen, hyphen D. Now let me provide some name for my container, let's say my Jenkins. And let me map the ports. See here I'm taking 7 thousand on my co-host and egg 00 on my container. So here, why I am taking 800 port on my container means actually we are going to run Jenkins on top of Tomcat application server. And by default, Tomcat application server will run on port number edge, edge rho, c, same port number. You can also consider on your Docker host to map with that. But if you remember, we already use that port for some other application. That's why on my Docker host I'm taking different port. That's fine. Now let me do CentOS images. So I'm taking CentOS. Now let me create a container. So container has been created. Now let me see that. Say this is the container just novae we created. No, let me enter into it. Docker EX C hyphen IT, then your container, let's say shall as bash. Now we are inside of your container. Now let me open ways, release information. And here one more thing. If clear command is not working, then simply use Control L in your keyboard so that it will clear your screen. That's fine. Now we are ready with CentOS container. What are the remaining requirements? We need to install Java, we need to install Tomcat, and then we have to download Jenkins application, and we have to copy that to Tomcat web apps folder. Now for these three requirements, actually we hold different steps. We have almost tool steps. No, let me go into these tools steps. The very first step is simply we are updating. Yeah, let me enter one by one. So you have to wait for some time for these setups than, than let me install APL release. Then let me install our Java. So it is installing Java. Once it is installed, we can verify that by taking Java if unwashed and command. Okay, it is done. Now let me verify the Washington. Yes, Java has been installed. The next thing is W get command. When it installed obligate because we need to download Tomcat tar file. So for that we need W get command. As of now, we are not having W get command with your container. That's why I'm installing it. Fine. Say to download your Tomcat is simply you can take this a step or go to your official Tomcat dot Apache.org website. And from there, go to your required motion. Let say suppose Tomcat mine, then here we have corruption. So here we have tar.gz. Simply do right-click and then copy linker does, then go to your container. And one more thing. So Here let me navigate into user local. And here I am directly downloading that they quite Tomcat nowadays downloading. So it will take some time. Just wait for that. So after that, let me go with next step. We will we will extract that file. It has been downloaded. No, let me extract it simply by taking. Now see that our Tomcat has been extracted. No, let me remove it anyway. I don't want that. Fine. Now let me rename that Apache Tomcat nine dot-dot-dot, whatever the version is that, that I want to rename it into, let's say Tomcat nine simply. Yes. Now we have Tomcat nine here. So after that, we need to export Catalina home. Let me simply follow this. Fine. Now we are ready with the Tomcat. Next thing is we need to download our Jenkins where phi. So for that what I can do is simply I can go to Jenkins website. Jenkins that I won't. So here we have a download option, click on that. And in long-term support we have Jenkins Java package that has a var file. Simply do right-click and select Copy link address. Then come here. See actually we need to copy that to Jenkins dot var file to web apps. So what I will do is directly, I will go to Tomcat web apps folder. Now. So here what I will do is I will download that var file. That's a simply, ok, fine. Now we are ready with our Tomcat and Jenkins var file. The next thing is we need to start our Tomcat. No, let me start it. Yes, Tom can has been started. If you want to verify, you can verify with PSI FF and E F pipeline grip, Tomcat. It is running. That's fine. Now let me come out from your container. Fine. See, we created a container by mapping 7 thousand port of your Docker host with age 0, NGO port off your container. Now whenever if you want to access your application, always you have to access that application with respect to two docker host only. Now, see, this is the URL to access your Jenkins application. Now let me go to my browser. So here simply I will take HTTP then docker host IP. So now this is my IP of my Docker host. Then colon 7 thousand poor ease off our docker host, slash Jenkins. I know it will open your Jenkins application. Perfect, it is opening. That's fine. Now we done with our setup and assume that this setup is done with our let's set test environment. Now, I need same kind of setup in my UAT, SIT ON also in product. So what we have to do, what are the steps to be followed in our test environment? Same steps we need to follow in our UAT SIT unprocessed. But actually it is a time taking process because anyway, to create a container, it is one step. But to install your jar, Tomcat and Jenkins, We have to follow these steps. So why we need to repeat these steps in different environments? So instead of that, what we will do is we will create our custom image such that that image should how our required Java, required Tomcat version and also required Jenkins. And by using that Docker custom image, we can create our setup with single-step simply by running this command. Now here we have two ways to create custom Docker image. They are using from a container and using docker file, actually creating custom Docker image using Docker file is very, very important concept. We will discuss that later. But for time being, let me go with a very simple way that is from a container simply by using this command now here to create custom Docker image from my container. Your container should now all your requirements. If you remember, we already done with all those things. I mean, if we go into this container, my Jenkins container, inside that jenkins container, you how your required Java Tomcat version and also jenkins. No, let me create a custom Docker image from my Jenkins container. Very simple, simply by using docker commit, by taking this container name or container ID, you can go with anyone of that. Now let me take container name. Now I want to create an image with the name, let say Jenkins with Tomcat setup on CentOS. Wanting to take this lengthen and just I'm taking for your understanding purpose. Fine. Now it is creating your Docker image, custom image. So it will take some time. Just wait for that. Because our container has a java Tomcat and Jenkins. Fine, it has been created. Now let me list Docker images. See that this is the image just now we created. Now by taking this image with a single step, we can create our required setup. In our required any documents. It may be test or UAT OR SIT or Proud. What I will do is let me remove this running container simply by taking docker remove hyphen F forcefully I'm removing because it is running. That's fine. Now we have these are the running containers and these are the images. So if you remember, this is our custom Docker image. Now I'm creating a container simply by taking docker run, hyphen IT, iphone DIE. Then let's say hyphen, hyphen, name my Jenkins. Then let me map the ports simply 7 thousand. I'm mapping with 8080, fine, then image ID or imagining. So what we have to take, we have to take our custom image. Now by running this command with a single step, you are going to do your setup. Our setup is nothing but simply this one. This entire thing we are going to do with a single command. Now see, Now if you go with your container, Docker EX easy hyphen IP, Bash. Now see that Java version? Yes. And let me navigate into user local. And here you see that there is a Tomcat mine. And go to that Tomcat web apps. And here if you observe, didn't kiss, is there? No, with one single step, we have done our entire setup. Now let me verify whether Tomcat is up and running or not. Generally it won't start because we created a custom image from a container. But whenever if you create a custom image from your Docker file. So in that case, we have an option to start your Tomcat automatically. We will see that while creating our custom image from a Dockerfile. Fine. Anyway, it is not starting now let me run our command to start the word Tomcat. Now you're, Tomcat has been started running. Now go and access your URL. I mean, to access your Jenkins application. So simply by taking HTTP host colon port number than Jenkins, see that now we are able to access our jenkins application. Fine. Now let me come more from your container. See now by using this custom image with one single step, we can create our setup in our different environments. Now it is very easy, no c. Instead of going with these tools steps, we can create our container with the requirements with one single step by taking this image. So that is the advantage if you create your custom Docker image. Okay? Okay guys, thank you for watching this video. 10. 10. Introduction to Dockerfile to Create Custom Docker Images: Fringe here or construct is building custom Docker images using docker file. Let me go with that. See, we already know that there are two ways to create custom Docker images. They are from a container that is with the help of Docker commit command and using docker file. And we already gone through our first method, that is custom Docker image with a container using the docker commit command. But actually it has some limitations. And one of that is it is not scalable and it is very difficult to automate the tasks in our real time. That's why it is not preferred in real time. Then the preferred way to create custom Docker image is using docker file. Now first let me tell you what is a Docker file. So in simple terms, Dockerfile is a script which contains some instructions or commands for our talker. And we can create a custom Docker image by executing Docker file with a Docker command called Docker. So simply, first, we will write some Docker file with some instructions or commands. Now, by using Docker, we will run docker build command on this Docker file. Simply, we are executing Docker file with the help of docker build command so that it will create a Docker image. See after that we know that, I mean, how to create a container from Docker image simply by taking docker run command, we can create Docker container from Docker image. Fine. Now here let me take our previous example itself that is deploying Jenkins application on Tomcat application server using Docker CentOS container. So actually, if you go with manual steps, we are having, these are the steps to create your set up. I mean, deploying Jenkins application on Tomcat application server using NACA CentOS container. But here what we will do is first we will create a Docker file. This requirement. And that Docker file we will execute by using docker build command so that it will create a Docker image. Now we will use that Docker image to launch our container with the setup. That's it. No, let me go with that. Creating custom Docker image using docker file C. We had to write our own Docker file to create a custom Docker image. So based on our requirement, we have to write our own Docker file and we have to know some important points to create a Docker file. The very first one, we need one base image to create a custom Docker image. So based on your requirement, you have to select this image. Now, we will select that base image from Docker official website called Docker Hub. And this base image information is the first instruction while creating our docker file. And we have to represent that with an instruction called from. Not only from based on requirement, we have different types of instructions or commands for our docker file. Some of them are like maintainer, run, ENV him in a neuron when exposed, command entry point and so on. And here, all these instructions or not case sensitive. Mean while implementing your Docker file, whenever if you are using these instructions, you can write these instructions in terms of lowercase letters or uppercase letters, but the suggested way is using uppercase letters only. And here, first I will show you already developer Docker file for our requirement that is deploying Jenkins obligation on Comcast application server using CentOS container. Now if you remember, while going with the manual steps to create our setup, we followed these steps first week later one CentOS container. Then we installed some packages and we did some modifications so that we got finally our requirement, I mean, our setup. Now here, what we are doing this for our requirement. First we are writing Dockerfile. From that we're going to create Docker image from that we are launching our container. Now, let me show you already developed a Docker file for our requirement. Now see here this is the Docker file for our requirement. Now if you observe this Docker file, the very first instruction is from. Now with the help of from instruction, we will mention our required base image. So with the help of base image only we are going to create custom images. And generally in real-time, they how they wound base image. So using that base image, they will create the custom images based on application. That's fine. Now here, often we were first instruction, remaining, all instructions or simply like you are manual steps commands. If you remember, these are the minute steps commands. So all these steps in play mentioned here. But along with that outtake and some where R1 and somewhere commands somewhere entry point. So we'll discuss about these instructions later. Fine. Now, this is the simple Dockerfile. Now let me create a custom Docker images simply by running docker build command. Docker build dot. Now here.me in the current location without Docker file. In case if your Docker file in the different location, then you have to mention the poppy here about your Docker file. Let's go to that location then you have to run your docker build command. And one more thing. Generally, we will take Docker file as in this way I'm only, I'm in capital D Docker file. You can also take any different file name. But if you take any different file m, then you ought to mention that file in here instead of dot. Even though if you are in the current location where you, how your Docker file, that's fine. Now let me run it. And one more thing before building your Docker image, you have to know one more thing. That is, whenever if you build your custom Docker image using docker build command with the help of Docker file. So what it is going to do, E's the base image, each and every instruction is going to add a layer. That's why wave bailing your custom Docker image. It will take a more time at very fast. But later, if you modify your Docker file and if you read on your docker build command, it will take very less time. I will show you that first let me run at very first-time our docker build command, docker build dot indices, simply docker build command. You are also having tags options. Those we'll see later. Now see the Docker build dot. Now each and every instruction is going to add as a layer on top of your base image. You have to remember that. Now whenever if you are going to create the very first time you were custom image with the help of your Docker file, it will take more time. Suppose later based on your requirement, suppose if you modify your Docker file and if we read on your docker build command, it will take very less time. We will see that. Just wait for some time to complete this command to create your Docker custom image. See that it is taking some time. Ok, it is almost done. Again, nearly, we need five more seconds. Find done. See once it is completed, it is also going to do the image ID here. See that? Or else you can simply run docker images and you can see that. See that let us image 148 anyway, it is not creating any tags or repository name. So that options you have to provide while creating, while building your custom Docker image with help of docker build command. That's fine. Anyway, to create your custom Docker image, it has taken some time. What I am doing is just simply, I'm modifying some instruction. Let's say I'm removing last instruction. So removing is nothing but simply, you can comment simply with the help of ash. No, let me save it. Now here, this instruction we removed, that is a meaning of hash here. Now if you rerun your docker build command, it is simply going to delete this layer on your existing image. That is why it is going to take very less time. Now let me renin, so docker, build dot c that it has done. Now, let me once again a modify simply by adding that line. Now already we have some image with these instructions. So on that image simply it is going to add the last layer. That's why it is going to take very less time. See that? So that point is very, very important. Then. Anyway, find, we created our required or Docker image from cent waste base image. Fine. Now see that Docker images, sorry. Now this is the image we have for our requirement. No, let me create a container using that image. Simply we know that command to create a container is docker run hyphen, hyphen D. Then let's say I'm providing name as Tomcat with Jenkins on St. ways. Latest. Then, you know, tom cat is running on the port number h 0, h 0 that I want to map with a docker host. Let's say I'm taking on Docker host also edge-to-edge report because as of now I stop all my running containers. That's why a journal entry report on my Docker host is available. Then finally, how to mention your Docker image ID. Of course, you can also mention ribose to rename, but here I don't have a positive name. That's why I simply am taking Docker image ID. Now let me run it. That's been created or container has been created. See that docker ps is running five seconds ago. So if you want to verify you are a setup, just enter into your container with the bash shell. And it will clear is not there, simply use Control L. Now. See that under user local, we how our Tomcat, Yes. And then inside that we how web apps inside that see that there is Jenkins dot val, or simply go to your browser and selective or IP of your Docker host. Undertake port as edge-to-edge hero than slash jenkins? No, it will open your Jenkins application. It is opening, right? So if you have a custom Docker images, it is very easy to create container at anytime with less time, right? So finally, that is the advantage with the Docker, Docker container radiation. Okay. Okay. Thank you for watching this video. Later, we will see each and every step of your Docker file to create your Docker file for your custom Docker images. Required. 11. 11. Basic Steps to Create Custom Docker Image with Name and Tags using Docker Build Command: And here we are discussing about steps to create custom Docker image with the docker build command and also providing name and tax for custom Docker images. Now let me go with that. See, we already know that that is docker build command is used to build a custom Docker image from a Dockerfile. Anyway, whenever, if you want to create a custom Docker image from a Docker file by executing docker build command, actually, we need to follow some steps. Now let me go with step-by-step. Now, very first step is you have to create a folder based on project or application. Let's say in our case, suppose we are going to build a Jenkins custom Docker image. And in that case you have to create Jenkins folder in your Docker host. Now here suppose I'm creating Jenkins folder. You can create anywhere on your host. Then after that, we have to navigate into Jenkins holder, and then we have to create a Docker file. Now let me navigate into my Jenkins folder. Now we're under Jenkins folder or directory. And here we need to create docker file. Now anyway, as of now, we are not good width how to create docker file. We will see that for time me again, I will use existing Docker file. Now if you remember, we have our docker file. Well, let me copy that into current location. Now we have our Dockerfile. Fine. So once if you how your Docker file in your required directory, then you how to run docker build command that is like the occur dot. Now let me run the occur in the current location we hope Docker file. So it will take some time because I'm going to execute it at very first-time. Actually, we created a Docker image from this Docker file in our last video, but I deleted all my old images. I want to create it from first. That's why I deleted old images. Now I'm running docker build command. So it is like you are going to run at very first ten. That's right, is going to take some time. Just wait for that. Once it is done, then we will list our docker images with the help of docker images command or simply Docker image. Unless we have two types of commands to list your Docker images. I will show you them. Kate is almost done. Just wait for three or four seconds. Then. Now, just now it has been a created a custom Docker image within the image ID. Let me clear my screen. See that to list1 Docker images actually we are using docker images command. Anyway, just now a week later, the image ID. And while running or docker build command simply we ran in this way, that way. This command is not creating any tags or name for your image. That's fine. And to list your Docker images, we have one more command called Docker image Ls. Both are giving same result. That's fine. Now, see that as of now you how your image without any tax or without any name, but assume that I need to provide name under tags for my custom images. Then in that case, you have to run simply. Now Corbay hyphen p, let say we are going to create Jenkins custom image, innovate that using CentOS. So you can write your options slash CentOS, then colon, whatever the tag you want to mention. Let say this is Washington, then space dot c. Now let me listed Docker images. So that CentOS version V1, this image anyway, without any modifying your Docker file, you run. That's why it going to take same image ID even for this image. Suppose I'm going to run once again by taking V2. But be clear, we did not modify the Docker file. So I'm rerunning simply docker build command with version two. Now see Docker images. For both the images, you house same image ID. Now what I will do is I will modify Dockerfile. Let's say I'm going to come in a last command, lost instruction in your Docker file. Let me do lasted two commands. Comment. No. We commented loss of two instructions in our docker file. So anyway, finally, you modified your Dockerfile. Now, I wanna create what shouldn't three. Now see the result. See Docker images. Now for you or version three, there is a new image ID because there is a change in your Docker file in case if you don't have any change and if you run your docker build command by providing your tags always, it will take you an existing image ID only whenever there is a change in your Docker file, then only it will create a new image ID. That's it. And one more thing. Suppose if you build in this way, I mean without any tax, then by default it will take tag as, let us say that it is giving tag as Latest. Or else we can simply run your Docker images and see that there is a latest image. So if you provide tag, then we'll take that. If you don't provide by default, it will consider that as latest. Fine. So that is the simple way to build your Docker images from your Docker file. C. We are also having one more command to build your custom Docker image. That is with the help of Docker image. Both will use same result. And this is very simple docker build command. So if you go with your official Docker documentation, there is a docker build or if you go somewhere down you how Docker image in both the options, you how Docker image bead or simply Docker build file. If you click on that, see that there are different options. So anyway, we are at beginning stays that way. I'm not going to touch them. Later. We will see step-by-step all the advanced uses of your docker build command. We haven't a lot of options with your docker build command. But these are, I mean, this is very simple, basic uses of your docker build command. Okay? Okay guys, thank you for watching this video. 12. 12. List of Dockerfile Instructions or Commands: Friends here our concert is different instructions or commands to write or create a Docker file. C, we are on the way to create docker file, but before going to create or write your Docker file, we have to know different instructions are commands. No, let me go with them one by one. The very first instruction is from. And using this from instruction, we can mention the base image for our custom image. Be clear. This is mandatory and must be the first command in your Docker file. Then next one is maintainer. So using this, we can write the name and email address of the image creator. Anyway, this is optional if you want, we can use it. Next one is run. So using R1, we can execute any command, our Linux command, and we can save that result as a new layer in our custom image sc agenda. We how to create a container from some image, but that image should have a let say, some package called in the next. So if your base image is not having package called Engineers, then using this run command, we're implementing your Docker file. We will do something like run yum install in Unix. So that in Unix package will be added as a layer on top of your base image. So that from that custom image, whenever if you launch your container, it will get automatically engineer package. So simply to execute your commands in your image, we are using R1 instruction. Then copy, actually for copy without two types of instructions. One is copy and second one is ad. But there is a difference between copy and add. Simply if you take copy that copy instruction, we copy a file from your source. Source here is nothing but your Docker host. A file or directory from your Docker host into your image. But if you go with add, it will do same as your copy. Along with that, we can directly download some file with URL. And that file you can copy it into your Docker image. Not only that, we can also extract tar file and then we can copy that into your Docker image with the help of ADD instruction. Anyway, we will see by implementing our custom images with the help of Docker file, then command, see, it can be used for executing a specific command within the container. Be clear. Whenever if you write some commands with the command instruction, those commands will execute within the container. So after creating our image, custom image, we will launch container. So inside of a container, if you want to execute any command, then we will use this command as the instruction to execute your commands. Then how entry point as well. See, it sets a default application to be used every time a content is created with the image. So actually there is a small confusion between commander entry point, but I would clarify that while implementing our Dockerfile based on requirement, I will take command as well as entry point. And sometimes both we will take. Then ENV, simply a neuron meant just to set some environment variables for your container from your custom image. Next, expose. See, it associates a specific PO2 to enable networking between the containers and the outside world. Then user. It sets the UID or username, which is to run the container. Then volume. It is used to enable access from the container. We had directory on the host mission. So as of now we don't know about volumes concept. So you may get confused here. So simply remember that there is an instruction called volume. Next work directory C. It said the path where the command defined with the command is to be executed. Then label. It allows you to add a label to your Docker image. So custom labels we can add using this label instruction. Then onboard a command that is triggered when the image in the Docker file is used as a base for another image. Here. You may not understand about volume or generically label an unbuilt, but we will see them when implementing our custom images. But for time being, just remember the names of your Docker file instructions or commands. So while implementing our Dockerfile based on requirement, you will be good with these instructions. Okay? Okay, guys, thank you for watching this video. 13. 13. Our First Simple Dockerfile : Friends here we are creating our first two Dockerfile c. We already know that Dockerfile is used to create custom Docker images simply by executing docker build command on your Docker file. Now here to write our foster Docker file for our custom Docker image. Let me take a small requirement. So here my requirement is I need to launch a container using open to 20 dots 0-4 version. An offer that my container should have Python 33 and a flat packages. So simply Finally, I will use this container to run some Python Flask application. Anyway, this is my requirement then how to write a Docker file. So anyway, after writing Docker file, simply build your custom Docker images by running docker build command. After that, from that custom Docker image, simply, you can launch your container by running docker run command. That's fine. And here, before writing Docker file, just for our understanding purpose, first I we launch manually container with 01 to 2004 base image. And then manually I will install Python three p53 and Flask packages. After that, those stiff simply I will convert into Docker file so that it is very easy to understand. I mean how to write your Docker file. Now let me go to my Docker host. So here simply, I'm searching for existing images. If you observe this output, we are not having 01 to 2004 image. So let me search for that. So simply by using docker search, open to, with a DAG S t dot 0 for C, you are getting some images, but I am not seeing exactly open to name here. They are with the combination of some other packages. So instead of that, what we can do is we can also go to our official Docker registry that is called hub dot dot dot.com. So here simply go to explore. And simply as such here using open to key. Now you are going to get our very first as some open to image and just open that anybody sees official image from your Docker. And if we go down, we're having different types of tags. And here, view available tax option is there just click on that. Then scroll down. See that there are different images. Tags. I mean, for this open to image, there are different tags. Now go down somewhere, you will get your required tag. So here we have a tag, 2004. And for this, there is already a command that is docker pull command how to pull that he made NPO docker host. So simply copy that and come back to our docker host, paste that command and then run it. Now see docker images. We have 01 to 2004. Now we have our required base image. Now let me launch a container from this first. So simply by using docker run iphone, IT hyphen D. I am not giving any name, simply I'm launching the container. It has been created. Now see docker ps. Yes, your container is up and running. So let me enter into That container simply by using Docker EX EC hyphen IT using Bash shell. Now we're inside of our container. Now let me verify, Is there any default Python with these host, I mean, within this container C that simply we can verify it which Python there is no Python or which Python three. There is no Python three. If Python three or Python is not there, then anyway, there is no chance to how Pip and packages. That's fine. Now let me install Python three on this host. So how to install your any package on your own to operating system simply by taking APT get installed. Python, I need Python three. It is not installing. So actually before installing any PAG is you need to update your APT repo equity get update. Now once if you update after that, you can install any package. So now I am updating that. So it has been updated. Now let me try to install Python three. So equity get installed Python three. Now see that it installing and it is actually asking conformation as Torno. So here instead of giving yes, sir, no confirmation is here in the command line itself while running APT get install Python three, we can provide hyphen Way option yes, conformation. That's it. So now it is installing Python three. It's done. You can verify it. Which Python three? Yes, Python three is there or you can also verify the West Chen. So you are getting Python 3.1a dot-dot-dot. Suppose if you want to get you are required to Python. Three dot 6370 here to mention that Python. Anyway, let us Python you are getting here. That's fine. Now let me install PIP three. Now if you want to install pip three, actually you need to mention with respect to Python. So now we have Python three, hyphen Pip. Let me provide hyphen byte. Now it is installing one pip package. So once it is done, again, we'll verify it. Just wait for sometime. It is almost done. Yeah. I'll see that. Which PIP3? Yes, PIP3 is there. Then actually what we need, we need Flask package as well. Now see that let me enter into Python terminal. So here simply I'm importing flask. Sorry. There is no package called Flask Python package with your Python. So if you want to install that, you need to install pip, install Flask. I'll see that it is installing your package package done. So what we did manually to get your requirement, the very first step is we have taken base image that has open to quantity dot 04. Then after that, we updated APT, APD get update. Then after that we installed Python. Three, then offer that we installed. Python three hyphen. Then after that we run this command pip install Flask c. These are the commands which we installed inside of your base container. Now for this requirement, if you want to create a custom Docker image, you how to write Dockerfile. So how to read Dockerfile, very simple for all of these steps, just to make an instruction in your Docker file, C. In our docker file. The very first step is always about your base image. Now to get our requirement, we are using this base image. Now, that base image information you have to mention as a very first step in your Docker file. And that is with respect to from, that's from the base image. We are going to create custom Docker image, right? And actually inside of this container, we executed all these commands. That means just to install these three packages in our container, we install these three commands. It simply take all these commands, whatever the commands we executed manually inside of your container and paste them. And for each and every command, you just to start with R1 instruction. Capital One. Of course, you can also add small as well, but preferred, we use capital letters or uppercase letters. Now here what is mean by R1 means while creating your custom Docker image, in your image, you are run will execute all these commands so that in your image you will get APT, get updated version. And in that image you will get Python three, Python 3p and then flask that say, now this is simply our docker file for our requirement. Now let me go to my Docker host. Let me come out from the container. So you whenever if you want to create a Docker file, always it is better practice to create some folder on directly based on the work required project taught application. Suppose here we are going to use this container later, let's say for flask applications, then let me create Flask app, then navigate into it. The NEA, just simply create a Docker file so you can take any name for your Docker file. But preferred way is using capital D Docker file. Then open that file and then simply paste your instructions. Let's see. We can also write empty lens, no problem, but let me remove that empty line. Save it. Then after creating your Docker file, from this Docker file, actually we had to create our custom dog remains so far that we have a command called The occur dot. And for your image, if you want to provide some tag's name, then you can use hyphen T. And let say suppose I want flask gap anywhere that I'm creating with the help of base image called Woburn, do then assume that this is very fast to Washington than simply I'm taking colon V1, that's it. Now it is going to create your custom image. The very first time we are running. Yeah. Cd stopping because we did some mistake. So what is that you see on each and every command at the end you need to provide confirmation. Yes. But for pip command you don't need to know. Let me modify our docker file. So it because of density is exiting with some ETL code. Let me open our docker file. The Czech. So don't forget to provide hyphen way at the end of your APT get install command. Okay, that's fine. Now let me rerun. So at very first time we are running this Dockerfile execution. I mean, we are building customers from this Docker file. That's why it will take some time. But later if have any modifications on this Docker file and if you read on your docker build command, within less time, it will build your new custom image from this Docker file. Anyway, just to wait for some time, maybe less than two minutes. It is almost didn't see that after completion of your docker build command, it is giving you a tagged, right, or I'll simply The occur images. See that just now we created this image. Now from this image, if you launch your container, human container will how your Python three, b, three as well as flask module. Now let me do that. I mean, let me launch a container using this image. So docker ps. So you just know we created this container, this is previously executed container. Now, just now we cleared this container, let me enter into it. Now.EXE Z hyphen IT. Container ID badge. I'll see that simply as such with the which Python three. But there is a Python. So which p53, p63 is there and go to your Python terminal and then simply import Flask. Yes, flux model is also there. Okay, so there is the simple way just to create a one simple Dockerfile for your requirement. So what is our docker file? This one. Okay. Okay. Okay, guys, thank you for watching this video. 14. 14. Dockerfile Creation to Launch Simple Python Flask Applications: Friends, here we are writing a Docker file to deploy Python Flask application in Docker container. Anyway, as usual, first, I will go with the manual steps to launch Python Flask application in container. Later, I will use those manual steps to create a Docker file so that we can create our custom Docker image. And from that using, with one step, we can launch our container to run Python Flask application. Fine. Now first let me list to the manual steps. The very first step is we need to launch container using any required image. Suppose in our case I'm taking image as open to 20.04. Then you have to install some required packages like Python three, p53, and flask. Then once it is done, then we will copy our Python Flask application into Docker container. So allergy, how a simple Python Flask application and this one. So I will copy this into container. So after that, inside of our container, we will run python three. Then you are Flask application name so that it will run your Python Flask application. So after that simply we will open a browser and we will access this application using its URL and verify whether it is working or not. That's fine. Now, let me go to my Docker host. So as of now, I am not running with any Docker containers and see that these are the images. Now, first step is we need to create a container. So let me create a container using our command called Docker run hyphen MIT hyphen D. Then let me take name as my Flask app. Then. So see by default, flask applications will run on port number 5 thousand. If you want to modify that, yes, you can modify in your logic, I mean Flask application. So as of now I'm running that Python Flask application on Python and port number. So I need to map my Docker host port number with the my Flask application port number. So simply are taken on Docker host. And I map with that with 5 thousand of Docker container Flask application port. Then as of now we are launching that container using open to, let's say $20 for this image is already there with us. Now let me run it. So container has been launched. No, let me enter into it simply by taking docker EX PC, hyphen IT, container ID then bash. Now we are inside of a container. Anyway. Once container is launched, we need to install Python three, p53, and Flask. If remember, to install all these packages first we need to update our APT Git repo simply by using APT get update, let's say hyphen byte, that's it. So it is going to update your API to get, once it is done, then we can install Python three simply by taking APT get. Install Python three. Confirmation? Yes. Fine. Then after that, by Tom three hyphen p. So let me probably confirmation in command line itself iPhone way. So once this Python three is installed, I mean by Dante and p3, then how to install Flask module for your python? We will install that. Just wait for a less than a minute. Then no, let me install pip install Flask because Flask is that required a framework to run your flask applications through Python. Then. So after that, we need to copy our Flask application into Docker container. Anyway, we already have a simple small Python Flask application. Now let me copy it into container. See VAR VM editors or not present with you are a base image 01 to 24. Then let me install anyone of that by taking equity, get install VIM, let's say hyphen wine. Because I need to copy it. No, I need to edit a file. Now. I am app.js file. So inside that let me paste my code. That's it. Save it and run it. What happened? Yeah, we're not having Python, Python three. So now our Python Flask application is running inside a container on 5 thousand port. But outside a container, we mapped that with a geoid 0 on our docker host. So this is my Docker host IP, then edgy right. Now let me run it so that we are able to access the Python Flask application. So manual steps are done. Now let we take all those steps. So let me stop my application, simply run history. Let me copy all these commands. We will remove unnecessary comments. So just for our understanding purpose, I'm taking all these commands. So here let me add a hyphen way. Then we install the VA anyway, if you want, you can install theater otherwise, no need to install. So once it is installed, we copied and then we run, ya know, these all are the manual steps which we used to launch our Python Flask application inside a container. Now actually, our intention is for our requirement, we have to create a Docker file so that from the Docker file we can easily create custom Docker image. And from the Docker image with one step directly, we can launch a container with Python Flask application. Right? Anyway, these are the minute steps. No, let me go and create a Docker file. See whenever if you want to create a Docker file, the best practices always create one folder with your application name or project name. Let's say I'm taking Flask app, then navigate into. Now here inside Flask app, we need to create a Docker file. So let me take a Dockerfile. So you can take any file limb, but Docker file is the southeastern name to create a Docker file C. Before executing all these steps, actually we executed all these steps inside a container. Before that, we launched a container using a base image called open to 20.04. So that is the first instruction in our docker file. Now let me write that from urban to quanti dot 04. Then after that, what is the first step which we executed inside a container? Simply API to get update hyphen white. This is a command, right? And we are installing some packages. So whenever if you are running a command to install something, that type of command you have to mention with instruction called run, that's it. So we have a number of commands here. Let me copy, paste one-by-one. So we installed Python using the line, be clear R1 we are using to install something. So whatever command you are using, if that command is going to install something than that command, you have to mention in your Docker file with the R1 instruction that's a. Then we installed a flask as well. So simply run. That's it. Anyway, installation part is done. The next thing we copied app.use anyway into our Docker container. But whenever if you're implementing a Docker file for that, what we have to do, he's in any one location on your Docker host. But Western practices where you have your Dockerfile in that location, foster create app.js. So wherever you are creating your Docker file in that location on literacy creative or Python Flask application, that's it. Now in the current location where we have our docker file there we have app.js. And actually we copied that app.use into container. But while writing your Docker file, we'll copy that file into Docker image. So for that we how an instruction called copy. So in the current location where your Docker file is there, that means dot slash. We have app.js that I'm copying into u r slash app.use a location. So inside a container, actually inside an image, we are copying this app.use with this name, same name I'm taking, but you can take any name for your Python Flask application in your image or in your container. Fine. So after that final step is simply we are running our Python three app.js, right? So simply these the command c. Whenever, if you want to run a command to install something, then we are taking R1. But actually, after launching my container, I need to run this command automatically so that I can access my Python Flask application. So for that, you have to take entry point. So entry point means after lunging your container, please run this command. But actually we have a lot of options with the entry point. By combining with command, we will see all those things in advance level. Okay, now let me save it. Now. Simply run docker build hyphen T. I'm taking my Flask app using open to base image. Let's say what SHA-1 as v2. Because already we have taken something correlate. Let me verify it. Previously. Bill images go here we are taking Flask app. Let me take the same name, but let me take wash. And as we do. So simply the off-current hyphen T 12, let say Washington as we do. Of course you can take say other name as well, but I'm taking existing name with Washington as we do that in the current location, our docker file. So it will take some time to create our custom Docker image from our docker file. Just wait for that less than two minutes, I think it will take because very simple Dockerfile. Once it is done, then with one single step we will launch a container so that automatically we can access our Python application, Python Flask application through browser using its URL just right for less than a minute. So it is running VIM. Then flask copying done. Now see our docker images simply by running docker images. So this is the image just now we created, no, let me create a container using the docker image, custom image. But before that, C, Use reports on your Docker to host these h 0, h 0. Now, this is the container which we launched with minor steps. Now I'm creating a new container docker run hyphen, hyphen D, Let's say name as. So previously we had taken my Flask app simply now I'm taking Flask app. Then puts, see already a user on your Docker host. Let me take on my Docker host port as 5 thousand. Anyway, inside container, our application is running on 5 thousand port. Then image is this one. So with one single step, our entire setup is done. That's it. Now clear and docker ps c that this is the container. Just know we launched with one single step automatically our Python Flask application is copied to Docker container and it is running. Now if you want to verify, take 5 thousand as the port, because that is the port we mapped with the docker host. Go to browser and take your Docker host IP, then port number as 5 thousand. See that now it is working perfectly, right? So friends, there is the simple way to create a Docker file for Python Flask applications. Okay? Okay guys, thank you for watching this video. 15. 15. WORKDIR Instruction usage in Dockerfile : Friends here or concept is what is work DAR instruction in Docker file? Basically it is for working directory. Now let me go with that. See, the VaR instruction is used to define the default working there three of your Docker image. Anyway, whatever you have default values with your Docker image, same values you will get in your container whenever, if you launch your container using that image. Now, to get more idea about work directly, work BAR, let me login into, let me enter into one of our previously launched container, let's say container. So simply Docker e FCC hyphen IT, that container. After entering into your container, immediately simply run PWD. Then what you are getting slash. So now for this container slashes the default working that at p, because after entering into your container, you are getting the path as slash, that is the default working directly. So same thing you have in your image. That's why you're getting in your container. Because from that image only you cratered container. Now suppose instead of slash, I want to take some different working directly. Let say suppose we are using this containers to run Flask applications. Now whenever, if I enter into my container than I hoped to get working there as let say some Python flask or some Flask application part. So how we can do that simply in your Docker file, you have to modify that and you need to rebuild your image. Let me do that. C, be clear. You are getting in our registering container default working directory as slash. That means our base image default working directory is defined as a slash. Now I want to modify that. Yes, you can modify that. Work. Var, let's say from default location Flask app. That is the path I want. Ok. Actually we need to modify the below lines as well, but we will see that. So first let me build image. So as of now we how images as in this way. Let me Docker build hyphen T. Now, Washington as we three. So image has been created and I'll see that images. And these are the two running containers on, on my Docker host 5 thousand and age range 0 ports are already in use. Now what I will do is using this latest image, I will create a container C, that Docker run hyphen IT, hyphen D. Then let's say iPhone, iPhone name, work, DIR, usage, then ports. So what I will do is on my Docker host, I will take 6 thousand port and I will map that with 5 thousand in my Docker container, then image as this one. See that? So docker ps. No, we created a container but it is not displaying here. Now let me see that in the exited container list. Yes, it is there. So it is exited with some error code. Actually the reason for that is, well, let me Doc open Docker file. And here I will explain. See previously we thought this line the default working directory slash. That's why while running this Python command, I mean, with respect to your app.js, non-incremental slash app PY. But no, you modified your default working directory into slashed Flask app, mature app.use away, not in this location, it is there in slash. That's why you need to write here slash. So even though you are taking what library as slash Flask app, still you're copying your files into root level, I mean slash app.use way. So in this location slash location or how app.js, that's why here I need to mention slash. Suppose if you don't mention slash year here and a here, then this file will be copied into this location. Because once if you define work directly, then offer that whatever the instructions we are getting like run copy, add entry point command. For all those commands, your Docker will treat location as this one. Anyway, I will show you that. Now let me save it and let me rebuild our Docker image. Now I am dealing with Washington as let's say we For it has been created. So images, docker, ps, iPhone q, sorry, hyphen. A. So what I will do is I will remove our exited container on Docker images. Docker ps now Docker run hyphen IT, hyphen v, let's say name as WordNet tree. You say. Then Let's say 6 thousand port on my Docker host, I want to map with 5 thousand. Then I want to use this latest image. Now see docker ps is working perfectly these up and running. Now, let me enter into a container. And after entering into your container, immediately see that you are in slash Flask app because we defined that directory. Right? And so I told that once if you define the word what their tea, then they run copy, add entry point and command instructions. Follow the work directory instruction, what it means. Let me show you that. See, once we if we define a work directly after that, whenever, I mean, if you are using copy or entry point command, add instructions or RUN instruction, all those instructions we treat the present working directory in your image as this one. That's why suppose if I don't mention complete path here and here, then your app.js file will copy into this location B to this name. And your Python three, we'll run this app dot PY bike concerning current working directory or present working directory as this one. That is the meaning of work mandatory. So if you don't want to copy your app.js into this work that it, then you ought to mention complete path. If you don't mention any pattern, simply if you mentioned a path and file name here, then from our docker host, whatever the file we are copying, that file content will copy into this file. But the file will be created in this word marital location. That's it. Now let me save it. And let me rebuild our image by taking v phi version. Fine. Now, the occur images and let's say docker ps c, why I'm running docker ps means I want to know which ports are used on my Docker host. Actually now I am going to create a new container with the, let's say work directory. You say two. Then ports. So already six thousand and five thousand, eight hundred zero ports are huge on my Docker host and 80 port is already used on my Docker goes to because I am running unix services as well. So what I will do is I will take 8 thousand port. Then inside of my container anyway, I will get my Flask application port has 5 thousand. Now let me take, let us the container and we launch today container. So docker, ps c, Just now we launched this container. So enter into that container, Docker EXE, you see, hyphen IT back. Now by default, you anyway, you will get your work that it trusts. Flask, App, Engine, app slash because that's what we mentioned in our docker file. And if you run ls command c, that add dot p, y is there here only, not anymore route. So here we are not having, right? So that is the uses of your work that at three. So be clear. Once if you define your work directory, then after that in your remaining instructions, if you don't mention complete path, then you what Docker will treat the present working directory as this work matter tree. And if you mentioned complete path wherever you need, then that path only it will take if you don't mention complete path, then only it will take work directory path as the default path for your remaining instructions. I mean, not all only for R1, copy, add, entry point and command instructions. Okay? Okay guys, this is the simple uses of your work directory. And actually we have a command called docker inspect. Using that command, we can verify the working directory of your container or image. Let me show you that very simple. Let me list containers. See this container we launched or using this image. Now let me run simply docker, inspect your image ID. Now you are going to get a lot of parameters here. As of now, suppose we need working directory and see that there is a working directory. This is the default working directory for this Docker image are able to see entry point as well. Now let me execute it for our container as well. So simply docker ps certainly take container ID. So docker, inspect container. Just scroll up somewhere. You will see working laboratory and also entry point as well. So docker inspect command is very useful to see the list of parameters about Dewar container or you are image. Okay, fine. And we can also define multiple working directories. But as of now, I don't want to make you confuse. But whenever situation comes at the time, I will use multiple times working directories. Okay. Okay, guys, thank you for watching this video.