Docker Tutorial for Beginners: From Absolute Basics to Hands-on Project

Analytics Vidhya · Beginner ·☁️ DevOps & Cloud ·11mo ago

Key Takeaways

This video tutorial covers the basics of Docker, including containerization, deployment, and orchestration, and provides hands-on experience with building and running Docker containers and images.

Full Transcript

Hello everyone, good morning. Uh, today we are going to discuss Docker. Yeah. So, welcome to this video and today we are going to discuss how to use Docker, why do we look into the hands-on of how to use Docker to build and ship your applications. So before we jump into the video, uh this is the what we're going to cover in this video. We're first going to look into the introduction part of the Docker. Then we'll just deep down into what are the deployment challenges which people face while building and shipping solutions and softwares into the production. that will help us in understanding what is de docker and then what is the difference between virtual machine versus docker then we'll look into why docker is needed right then we'll deep down into some of the architecture of the docker we'll look into some real life use cases of the docker we'll go into the setup and installation and last we'll look into the hands-on part of dockerizing and streamlit app right this is going to be an like an app which we build in local and then we'll build it into a docker container and then ship it. So that's all we're going to cover in this video. If you want to know how to build this uh app in the docker, how to use docker setup, please watch this video till the end. Okay, let's get started. So the first thing is what are the different kind of deployment challenges which people face while building any software. So first one is it works on my machine syndrome. Okay, as you can see and guess from the world itself, right? And this is the major challenge which most of the developer faces. It works on my machine but it's not working in stage or in a production environment or this software piece was working fine in my local but now there's it's not working in when I'm trying to deploy it in another solution. Okay. And that's a major problem and the major reason is different kind of environments has different kind of setup or probably different environment is there because that might not be present when you're building a particular software and that can lead to the the the app is not working or performing as it should be right and if you want to understand the whole life cycle of a software look into this right like first you're going to build an application you're going to write a code then you're going to test it in the development environment or maybe in your local when you are going to test it in the testing kind of environment right where you're going to validate not even only the code but you're going to look into the functionality testing then you're going to deploy that code and then you're going to monitor how it is performing in production and if anything goes down then you're going to take uh it as a you know step towards finding that bug solving it and then resolving that issue and this goes on right And that's why you need certain automation and certain systems which can help you to do this thing much more faster. Also another problem that can happen here is different kind of libraries and different kind of uh softwares that is getting used uh there could be mismatch of that right and because of that your code which is working perfectly fine in your local machine might not work outside of this and major challenge is like when you're building any solution or any app it requires lot of different kind of complex uh softwares packages dependencies Right? Sometimes you're looking for database. Sometimes you're looking for a particular API that can be called or you're looking for some underlying operating system on which you're building that particular application, right? And those things uh might require different kind of uh configurations, runtime packages that needs to be installed manually, right? For example, if you're building uh uh any uh you know basic ML package, you might require specific packages like scikitlearn, tensorflow, pytorch, right? And then you need to install them. If there is any kind of uh error in and in installing that packages, it can lead to an error. Also when you can see that right all the steps are manual in nature that means someone is actually performing it. So it prones to more lot of human error and sometime it's hard to replicate. You might have heard of it right. We have got a bug but we are not able to replicate it because the kind of environment in which that kind of bug has come you might not have the same kind of environment or the condition setup. So this is again an another kind of deployment challenge which is been faced quite frequently as we have discussed right like many people uses different kind of laptops or systems to build their application like for example I'm using Mac but somebody might be using Windows somebody might be using Linux kind of OS and you are using a different kind of operating system to deploy your app right somebody might be running it it in uh Linux somebody might be using that application in Windows So to have that OS specific behavior uh can uh you know you need to be very sure that your application works really fine in different kind of operating systems and that can lead to another kind of challenge. How you going to build softwares which is OS agnostic also it's very hard to port any application which you have built just on a one particular operating system and then you want to migrate it and run it in another operating system. Testing these kinds of applications requires some kind of resources, right? Like for example, you have built an LLM based app and you want to train it, right? So you're using some GPU machines, but the same time you are using some analytical software which you have uh used for tracking, right? Or for building any dashboards. Now if you're running both of them in a single machine, you need to have different kind of compute resources and you might end up using both the uh you know resources and might be your ML system is working but then analytical app is not working and vice versa can definitely happen right and then the overall cost of running those applications might shoot up and you will have different kind of challenges in making sure that you're able to run different kind of use cases in a single system or single hardware. So these are the different challenges which is there uh file deploying or testing out your applications. lack of isolation as I've just discussed right when you you're building a one particular app it might require different kind of uh solutions and if they are not isolated one particular error can lead to another uh you know software or piece or functionality not working and it can lead to complete failure of your applications also sometimes it can leak to lead to the security risk as well and resource conflict because all are running in a single system scaling is a very tedious task right now. Imagine you're running all this manually setting it up and you know making sure your application is running in a one particular system and you want to scale it for thousands of customer. You have to replicate the same kind of effort manually and it is very hard like you can imagine the amount of effort would be required to scaling it up all would again be quite manual and tedious. It can slow up your scaling part may you know if you want to scale your business even if you want to scale it uh from an infraite it could be lot tedious and last what about the roll backs right like if something goes bad in production when you're deploying let's say a new software release and if something breaks how you can make sure that you roll back to the previous stable version in a fraction of second without impacting your production these are the major challenges challenges which you're going to face uh when you have to deploy any software for that what we have is docker >> just a quick note analytics vidya has 100 plus free courses from beginner to advanced on topics like machine learning generative AI agents etc complete with certification click the I button to explore now >> yes Docker allows you to have this thing where you can develop applications, write your code in a particular environment wherever you want. Then Docker provide you this functionality where you can ship your application, package it really well and you can share it with anyone in the world. Then you can test your application, right? So you also want a same kind of environment and system where you have built that kind of application, you can even test it. And last you can seamlessly release and deploy your application into the production without even worrying about how it is going to run in production. So Dockers is an open platform for application development and deployment. It also works as infrastructure as code and we're going to see what is infrastructure as a code. It supports your CI/CD pipeline which is continuous integration and continuous deployment. It is faster code to production right. It manages all the different kind of overheads that we have discussed the challenges which we have discussed previously and it allows you to write code faster and put this into production faster. It's portable, efficient and automated. That means you can build anywhere, you can ship it anywhere like you don't have to care about the platform and the infrastructure. So before we jump into how Docker works, how we can use Docker to build our application and ship them, first let's understand the basic difference between Docker and virtual machine. So how does virtual machine works right and if you want to look into you know just to give you an example right what is virtual machine so virtual machine is any kind of uh machine or like a system that you can access it virtually that means uh if you would have logged into somebody's system remotely that you can treat it like a virtual machine let's say when we log into any op operating system which could be Linux, Windows and any other and we go to the cloud right and uh someone would have run that machine and we can login from our system by not even physically there like right now you might be watching it in your mobile phone or your laptop or your desktop right that's an actual hardware because you have the CPU monitor everything running and uh the hardware software everything is with you so when you're accessing it it's not virtual. But now let's say you can login into any machine or a system from your uh desktop or laptop and can access and run uh any software or watch any video or run any code into that system which is running somewhere remotely, right? Like it could be anywhere in the world that is like a virtual machine basically, right? And uh virtual machines are basically used uh so anyone can access any kind of resources uh even when they're not uh having physically access to that machine right and yeah like those who have worked on virtual machine will understand it much better and just to give you another example right you can think of uh many people have done it before uh when we run different kind of operating system in a one particular machine let's say in my PC I can run uh Windows and Linux OS at the same time. Why you will do that? Right? And there's a various reason because different operating systems uh might support different kind of applications that is required for the businesses. Let's say I want to use Microsoft Office. Uh so I need Windows but at the same time I need to run some of my ML or analytical software which or maybe a GPU based application which just which can only run in Linux, right? or I have specialized software which which only runs on Linux operating system. So what I can do I can install both the different kind of operating system into my machine into my laptop or a desktop and I can login into that virtual machine whether when I want Windows I can login into that when I want uh Linux I can switch that right but what is happening behind that right if you look into it there's an hardware component right like you have in physical hardware which is your operating system that is hosting sitting on top of your hard disk RAM right and uh whatever processor you have used to for the system now that operating system on top of that host operating system is going to talk to your virtual machine or the guest OS which you're installing right so for example you're installing Windows and at the same time you have installed uh Linux on a particular machine there's a hypervisor who is going to make sure that you can communicate to both the oss So basically what is going to happen you're going to partition your hard disk and RAM accordingly. Let's say you have 100 GB of u space. So you're going to make give 50GB to one particular OS or 50GB to another OS or you can do it vice versa like or maybe differently like you can keep it 40 60 30 40 sorry 30 70 like that right basically what you're doing you are partitioning your resources to different oss and different application can access that much resource only. What is going to be the challenge in this? Right? Your one particular VM can only have access to that particular resource. It cannot have access to another OS, another resources. So if you run out of memory on that particular OS, you have no other way either to repartition them or use some external hard disk. Right? Same with the memory. You can't get more memory. And that is the biggest challenge of virtual machines where let's say if I'm running uh one particular applications which might require few GBs of memory and there's an another application which sometimes require few GBs of memory but during some load and some batch when I'm running in night it require more resources now I cannot cater them at the same time because I have already partitioned 50/50 of my virtual machines. So I cannot give them more than the 50% of resources even if it is ideally ideal in another OS right so I hope you you got the gist for that but docker solves this problem really well how do solves this problem basically in this we are not having this partition of the physical uh resources so how that works let's say you have one particular hardware you have operating system on top of that there is a docker container that is running Now in that docker container you can have different kind of containers that is floating and running on top of that engine like container sorry your docker engine can host uh different containers this containers can have different kind of application and configuration so for let's say you can run a Linux kind of operating system and app which supports Linux right inside this container at the same time you can use an windows kind of operating system and the windows app that you want to run on top of that you can do that and both can run at the same time. Now what benefit this will have is this is like you can think of these are container but they are fluid in nature. If you want during runtime or when you're building this uh containers uh uh right you can increase the size of this containers you can use it if you they want more resources you can allocate them. you don't have to go for the uh again partitioning them when you are doing it as in virtual machine right so that's a basic and biggest challenge uh when you're using virtual machine that the resources are constrained it's stick to that OS where containers are not OS agnostic like they are basically do not depend upon the base operating system on which your system is running they generally works on the application layer whereas Whereas virtual machine is the virtualization of a OS plus uh application whereas containers are basically virtualization of your applications layer. This I hope that gives you the clarity between the virtual machine and the docker and that explains why use docker right why docker is so much powerful than just using a virtual machine but that does not make uh this that there's no virtual machines getting used and you don't need virtual machines virtual machines are useful but docker gives you more flexibility and that's why you see that uh we are using dockers in most of our applications s uh because it gives you that flexibility and other ch uh other benefits as well which we are going to see now. Why use docker right? So if you see this docker containers provide isolated environment and application as we have just seen right the docker engine provide you that functionality which isolates with the OS also containers are lightweights and efficient in use. So they are pretty much lightweight as compared to actually deploying a complete operating system. Secondly independent right like containers eliminate this dependency on the host that we have seen. So you can independently run any application any kind of uh [snorts] you know uh dependencies if you have right you can just run that inside that container. Everything is packaged inside it. you don't actually have to uh think or maintain them separately. Concurrency multiple containers can run simultaneously. virtual machines you could have run two three like it's very difficult to run lot of virtual machines in a single system until like you have very big uh system uh which can handle a lot of thing but again that's a bigger challenge because you have to maintain them and manage them manually where here you can run as many containers as you want and your system can support and you can concurrently use them run them right uh you don't have to just say that I can just use one OS at this point of time like if you as an user can run both the uh containers or multiple containers at the same time consistency this is the biggest thing if you can think of right docker ensures consistency across different environment if you're running a particular container in an Mac OS or a Linux OS or a Windows OS it is not going to have any kind of error because it's a container right whatever inside it will get executed seamlessly and sharability you can easily share the containers uh to outside world and we're going to see that how you going to use the docker uh and share your docker images outside. So that's pretty much covers like why use docker and why docker is very much powerful. Now let's go into little bit of uh the dockers life cycle right and uh as if I talk about right dockers provide you the tooling and platform to manage the containers right so basically as I talked about now everything is like a container basically your app becomes uh uh gets exploded uh you know inside a container and then everything is a container basically now you can develop your app and its component inside a container so basically contain Containers become a host for your applications to run. Containers serve as the unit for testing and distribution. So basically containers help you to test your application and distribute it. Now deploy containers, you can basically deploy your containers in any environment like you want to run it in your local data center, you want to run it in some cloud platform or some kind of hybrid infrastructure, it will work exactly the same. You don't have to worry about it. Also it works as we have discussed right like based on different operating system or even any cloud platform it works same and if you look into this part right these are the basic uh functionalities of a docker it provides you the development part you can build the containers you can ensure that the containers functionality remains same you can distribute them anywhere you can deploy that in various kind of environments and then running containers consistently across environment you can run mult multiple containers at the same time. Now let's jump into the Docker architecture overview. Right? So if you see Docker follows a client server architectures as you can see from here and some of the major core components of Docker. First one is Docker CLI like you know client interface uh line interface. [snorts] The second is the Docker demon right. The third is the docker rest API. Then the docker runtime and the docker registry. If you just look into this architecture overview, right? As we have just discussed the one the docker basically is an application which runs on top of your host operating system. Right? And not only that it is going to run a server inside it. Right? This is the main core server and there are docker application basically right the client is interacting with using the rest api and everything runs inside this container uh inside this server and uh basically all the containers and images that are getting formed runs inside it. Now this application manages images and containers. So uh we're going to talk about that what are docker images what are containers in sometime but just think of like images are some runtime file and instructions which docker follows and based on those images and instructions it is going to uh create that container when you execute that and run it. So image is basically like set of instructions which it just memorized that this is what we have to do. it follows that and creates a memory map and then when you execute it run it it creates a container in which the applications run. Now that there are two things which you're going to look which you're looking here we'll go into more detail in our uh next uh uh slides. One is the data volume. Now as you can see like docker is running inside uh all the containers and everything is running inside this uh server. it needs to communicate to outside your uh system right the host OS for that if it needs to communicate to an external uh space right let's say uh a particular folder let's say E drive C drive or if you it need to access or manage to a particular port let's say you're running an application inside this container but how it is the host OS is going to communicate with that you can manage the network and data volumes using this so this is the overall architecture uh of the docker. Let's jump onto the official documentation of the docker. Right? If you go and search on the Google uh docker, you will get uh this official website of the docker that gives you uh how what is the docker, how to use it. And once you go into this docker.com you can see you can learn how to use docker what are the different uh things docker provides you right like it it can tell you what is docker docker helps build share run and verify applications anywhere without tedious environment configuration and management and this is what we have discussed so far it helps you how you can build a docker containers how you can share it how you can run it how you can verify it, how you can test it, all these things are provided to you. So you can do that and you can see it has been used by almost 20 million plus monthly developers, 7 million plus applications, 20 billion plus monthly images pulls uh through the docker right this is a huge number and industrywide use tool. Now let's go into the documentation of the docker right like how the first one is how to get docker how to install docker right if you go to this uh docsd docker.com or even if you are here you can see how to download like cl like get started how to download it so you can just simply download it's an opensource so you just come here then based on your operating system so if you have a Mac you can click on Mac now you can again Mac gives you different kind of uh so uh OS uh chips right like if you have an Apple silicon one you can choose this if you have Intel chip one you can choose this and uh if you are having a Windows operating system now again based on that what kind of uh OS you system you have uh you can choose uh to download the docker application directly you can even for Linux you can run it and you can download it Now uh once you download this it will you can follow steps and then you will be able to download this docker. Once you download this you will see this your docker will uh come as an application. As you can see here I have already downloaded it. So I have this docker applications already there. It will take some time and it will load. And if you can see there's an icon showing at the top docker running in resource saver mode. So if I'll go to the dashboard, you can see my docker app is here and it can show you what are the different images I have I have and it in running what is the container that is already running uh what are the volume things. So we are going to come all to all this thing little later on but you can just download your docker and just run it and start it. Now coming to the docker right like the docker platform and the architecture which we were talking about. So let's look into this architecture. Docker allows you this uh kind of setup as we have discussed right where this is the host where uh this kind of app this is just an application but this is running something in the back end right this is the host which allows you the demon is running. Now when I started the docker the docker demon started and you can see here right like docker desktop is running. I can pause it, restart or even quit the app and I can close the docker. This demon talks to the client, right? And client is the interface either it's a CLI, right? Like command line interface or is this application which is again a client. So basically docker desktop is nothing but it's like a uh com like an interactive tool which which I can communicate to the docker demon. I can write some commands through my command line interface or I can use this application to send this commands. What do demon do right? It understands that there are going to be two components for me. One is the images. So all different kind of images basically the instructions and things which we're going to talk about later on. It communicates to those images and build those images and once I write the command it runs the docker containers as well. Right? And now this not only runs internally, it communicates to the docker registry. Right? As you have just seen right now that these were so many containers and images that has been built uh historically. All these are available in the docker registry. If it's a public docker hub then there's a docker hub that is there which is a public domain. Uh you can maintain your own registry and images internally as well. Now all these images are present. you can pull those images and run it. If you have some images that you have built, you can push them back as well to the world. So basically, Docker uses a client server architecture. Docker clients talk to the Docker demon which does this heavy lifting of building, running and distributing your containers. Docker client and demons can run on the same system or you can connect a Docker client to a remote Docker demon as well, right? Like you can communicate to outside as well. Docker client and demon communicates using a rest API over a unique socket right basically that's where uh we have talked about another docker client is a docker compose and lets you work with applications consisting of set of containers so if you have more than one containers then docker compose is being used what are the major components uh of this docker architecture as we have just discussed right the docker demon and also called as docker d which listens to your docker api and manages all the different uh docker objects uh such as images, containers, network and volume. Another is docker client, right? Like this is a specific client which you give us command line interface and it communicates to your docker demon. Docker desktop, right? We just saw that like this is the docker desktop application which allows you to talk to your docker demon. Another is docker registry, right? I can take you to the docker registry. What does the Docker registry looks like? Docker registry and this is the official Docker Hub registry right you can see this is the Docker hub and there are multiple images uh of different kind of applications that you can think of like for example Python, PyTorch, Reddus, Postgress like you can think of any tool software or application you will find those images here. So basically Docker registries allow you to store the Docker images. Not only store pull those Docker images and use it for your applications. Okay, these are the major components of the Docker. Now let's look into some of the Docker objects, right? As we have discussed. So first Docker object is images. Okay. Now before we go into the images, what does a docker image right? Image is nothing but it's a just a read only template with instructions for creating docker container. Right? You must be thinking like okay we are talking about like docker images but these are just a simple file and exactly yes it is just a simple file with lot of instructions that we might do manually and I'll show it in the demo in a couple of minutes how to build a docker image and often an image is based on another image right sometimes that's what we have discussed right you can run an windows OS in an Linux machine so from where that Windows OS will come right this is where you can pull that image so that's what it is kind of referring offering an image is based on another image with some additional customization so let's look at an example right for example you may build an image which is based on the Ubuntu image but install the Apache web server and your application as well as the configuration details needs to make your application run right so what it is saying you can pull that Iuntu image install an Apache web server maybe build your Android or any kind of application on top of that if you have to run it and then you created your own customized image and then customized image you can share it with anyone whoever will run that application will automatically have an Ubuntu server an Apache web server running and your Android application would be running on top of them that's your customized image right so we'll look into this example just after this and then things will become more uh you know clear. You might also create your own images based on that and then you can you can publish them into the docker registry as well. Right? So anyone in the world can use it. So that's how it works. Each instruction in docker file creates a layer in that image and when you change the docker file and rebuild that image only those layers which have changed are rebuilt. Right? So basically whenever you're building an image uh anything any changes that you're making only that will be reflected not everything in total. Another uh major object of uh you know of the docker is container right that's what we were talking about so time so many you know times that we have talked about containers containers containers is nothing but anunnable or instance of an image or like an executable instance of an image when you run that image containers get started and whatever is running inside that container will be basically your application ation or the system that you have created. So basically you can create, start, stop or even delete a container using your docker API. You can connect a container to one or more networks and that also we have talked about right in our slide where okay you're running a container but then how you going to connect to the operating system? How you going to access it? If you want to store some data or read some data from your host operating system, you can attach in storage to that. Right? All this thing can be done uh inside your containers. So containers is defined by its image as well as the configuration option you have provided when you starting it and running it. That's all. When a container is removed, any changes to states that are in stored in persistent storage disappear, right? Like when you kill that or remove that container, everything that was there just goes out of that. And this is just an example how to run a container. We'll look into that in our uh next section. Now when we have looked into the docker architecture uh let's first look into some of the major components again uh of the docker. So the first one is the docker image right as we have talked about. Uh there are two major principle of a docker image. One the images are im immutable right. So once an image is created it can't be modified. You can only make a new image or add a change on top of it. Right? So basically you go back to that old file make the changes build that image again and create a new image that's all you can do right also container images are composed of layer so each layer represent a set of file changes that add remove or modify file right so container images has that layer thing just to have an uh as an example right so if you do docker pull or docker push any image name you can pull and get that image from the docker hub or any registry Same way if you want to push your image to any registry, docker registry or docker hub, you can use docker push to do that. Secondly, if you are building any uh docker image, right, these are the some command line tools and I'll show you in the app also how to do that. So if you run docker build dot right and dot means your docker file should be there in that particular repository or you can give a exact name also right docker build and uh python t and then you give the image name let's say my name and image name and dot right that will create a docker image that's how you can create a simple docker image then coming to what is docker containers right uh containers again as we have already discussed it's an executable Docker image. It's self-contained because each container has everything it needs to function. Uh there's no reliance on any pre-installed libraries or any host machine. Isolated because each container run its own isolation as you can see here. They have a minimal influence on the host and other containers. So increasing the security of your application. Second independence like it can manage its its own portable. So containers can run anywhere. So the same image if you have built in your local you can share it with outside and containers that run on your local can run anywhere outside as well. How to run an any image? You just define the docker run command run it and define the port. Let's say as I discussed right if you have to uh run it on a specific port and you want to open that port you can define and do the mapping of the ports and then define the image that you want to run and it will run that. Coming to what is Docker registry? Uh Docker registry as I just showed you, it stores and distribute your Docker images. Public registry is like Docker Hub which anyone can access and download it from here. Private registries are there would be like you know some GitHub, AWS, ECR or some you can have your own private repositories for your specific apps and uh solution that you have built and command and interface can help you to pull and push your images to that registry. How to do that? Again very similar command for docker pull and docker push and at high level docker architecture right. So basically these are the two uh three major commands that helps you to run and build any image any containers. First is docker build basically that allows you to build an image. Now sometimes you use docker pull to pull that image automatically that has been built by someone and you just want to use it. So you do this docker pull and then another is docker run. Now if you see here when you run docker build this command line interface request goes to the host and it builds an image that's it right you can see an image got built here is if you look at this uh arrow docker pull command actually asks docker demon to go to the registry wherever that registry is if you have already connection set up you have it will go to that registry and build that image for you. So now that image is coming up here and getting stored in your local event. When you say docker run and write the name of that uh image, it is just going to execute that image and then we'll start that container. This is how the flow works. To look into this, if you want to understand now this is my container and this is my image. So if you go to any image that is running you can see there are list of instructions that has been already set up and written in it. So these are the layers basically right like first one add this run this command line uh this is the environment setup copy this docker file from here to here uh run this copy from set up my working directory and so on right so these are the some of the instruction that has been written in the docker image same way if you look at into the containers you can get all the logs of that container you can inspect and see uh how what are the instructions that is there you can see if there are some files that is there statistics around the data from how much time it is running right now it's not in running mode uh if I'll run start it it will get executed and so on right so this is the difference uh if I'll go to the docker hub so you can go to docker hub and connect from here in your uh you know docker desktop as well and I showed you the image also how you can get it let's say if I am using lama and I want to use this lama image how I can do I can just pull this image image right? So I can run here pull click on it it will start pulling it. If I execute this it will pull and then start running it and if I have to do it through the command line interface how I can do if I have to run it for CPU only mode I can run it like this by after installing it and running these commands. So these are some of the basic uh functionalities of uh and things that is there for the docker. Okay. Now you must be wondering uh how to you must be wondering okay now you must be wondering we have looked into the architecture of the docker how to create docker image right like how to build the docker image and that's what we are going to look into it so if you see now what is docker image uh before we jump onto the hands-on part docker image is basically set of instructions right and uh this is how you can think uh the instructions are the first one is from right so from image now this defines your base image this is something which is very similar if you're pulling an image from a docker hub or a docker registry so what you can do you can write like from and the image name and that let's say for example you want to uh pull a specific image uh for python right or you want to install a particular OS uh let's say you want to install a Linux OS right so you can just run this command and it will automatically pull that image for you. Okay, so this is the first thing and this is almost the first command when you are creating any uh you know docker image for your use case. The second command that is there is run command. Right? This actually helps you execute any command in that layer. Right? For example, if you want to execute or run something, if you want to execute a Python command or if you want to execute some cell script or you want to have some kind of commands that is required for your program, right? All this thing can be uh executable uh through the run command. The second kind of command is like working directory. Right? So with this uh you can set up your working directory and you can run any command inside it then right for example run command entry point copy add instructions right to do certain things. So all the different kind of activity that you want you can run it. So with this you can set your working directory. Now this you need to understand why working directory uh docker is going to have its own uh space right in terms of the storage in terms of the file system and the kind of OS you're going to install like for example if you're installing in Linux OS it is not going to have like a C drive D drive kind of format it is it will have the user/ uh you know the basic uh app or a root folder it will have right that's how generally you will see the kind of file system that generally is present. Now in order to access any file from there or copy your data, you need to know the file system. That's why you setting up the working directory here. Now another kind of thing that is there is the copy command. Copy is going to copy uh some files from your local file system into the docker. Yes, that is this is very much important because it is going to uh you need the all the file system that you have, right? That uh you want to run. Let's say you want to run your Python file uh which is uh you know uh abc.py. Now how uh docker will be able to execute or run that python file if you're not able to find it right. So copy command will allow you to copy all the files that you have in your local to your uh actual thing that where you want want to run it in the doc docker image. Another kind of command that is there is uh command right like this uh defines the default program that is run once right so this is like an entry point and then it is the default kind of command the or a program that you want to execute once you start the container so this is the base so each docker file only have one cmd and only the last cmd instance is respected with multiple exist right even when multiple exist only the last command is being used. So this is very much important because your com container is going to be an executable uh instance. If it is not going to uh execute anything or build anything right uh then yeah it will just be a same container which has nothing to do basically right so in order to run your application you need to pro provide the command at the end using the cmd command. So let's look at this one example we have right now. We have this set of instructions and with that you can see here at the right hand side we have a sample docker file that we have built. This is a very simple docker file that we have built here. Let's look into this one by one and then we're going to execute this uh and then we're going to use this executable file for our use case. So the first uh line right as it is mentioned from Ubuntu col22.04 that means it is going to pull the docker image of an Ubuntu or operating system. So basically Ubuntu operating system is something which we are going to install as our base image right and then we are going to run certain commands on top of it. So this is going to copy Ubuntu file system or uh Ubuntu operating system into your docker container. Second command that is there is install any dependency or app dependencies that is there right. So basically what we are going to run here we are going to run apt get update and apt get install python right and then python pip. So what we [snorts] are installing here first we are updating if there are any packages that is uh you know required in the Ubuntu file system I'm installing that second I'm installing Python right because if you have to run some Python script or if you are running some app building an app what you need you need Python right that's what we are going to run and have that then we are installing pip here this run pip install flask right it is going to install the flask version uh 3.0 O right it is going to have any advanced version and uh that is going to be there then it is going to copy the file so now we are what we are doing we are copying the file hello py into the file system then we are uh just doing the final configuration basically we are uh having that environment flask app is equal to hello exposing the port and then the last one that we are running is we are running this flask container on the port 8 thou 8,000 like 800 0 we are running this on this. So this is just a syntax of of one kind of docker image that you can see even if you look into [clears throat] the docker hub that we have right let's look into one of the docker hub image that we have for python so if you go to the python and you will find it there are lot of images that is already present with this you can even run in the docker desktop right any particular python version that you want right there are multiple versions of python that is available you can pull it and you can run it as it is required And this is a very basic uh simple Python docker file that is present that what it is doing basically if you see here it is first pulling the docker uh image then it is setting up the working directory then it is copying the requirement.txt txt file. Then it is installing all the packages that is present in the requirement.txt. Then it is copying all the files that is present in that local directory into the docker uh container. And then last it is running your python script with the command prompt uh like cmd python and your whatever your script name is right like the file name is it is going to run that script. So this is how you can create a docker image and can create a docker container. So let's get into the hands-on part. What we are going to do, we are going to create a docker file and then build a python app uh using that. So for that you can open any ID. Uh you can uh create a very simple Python script. So let me create a very simple Python script first and then uh I'll show you how you can execute this Python script. uh into uh a docker container. Okay. So before building a script right what we are going to do here we are going to uh build use uh either you can use flask or you can use any other uh way to execute a python script for our demo. I'm going to use a streamllet based app. Okay. So what is streamllet? If you want to know more in detail you can google it. You can go to streamllet.io io and you will see that this is again a very famous package that is used uh for building and sharing your uh python apps and it has lot of different functionalities. How to use streamllet is a very very simple way. Just import the stimllet package and then if you do streamllet uh as st importing the package and you can write uh you can create uh simple dashboards, you can create uh different kind of inputs for the users like say an input box. You can create a simple button to get any action done. Right? If you have to host any ML model, if you want to build an app that can be used for any kind of user interface, you can build that a very smaller app. Even you can build generative AI and LLM's kind of app here as well. But we'll not go into this uh uh detail. What we're going to do, we are going to build a very simple uh streamlet app. So I'm using basic uh copilot here. So that will help me in getting the work done quite faster. uh build a simple streamllet app right so again a very simple app let's say uh it's going to build so now what it is doing it is building a very simple streamllet app let me uh walk you through the the code if you see here what we have built we have a simple streamllet as st so basically what we are doing first we are importing the streamllet package Now in order to have the streamlet you need to install that. So first what we are going to do uh let me just rename this file. Let me create a python file as app. py. Okay. And let me have this code here app. py. It has the streamlet app. And then what first thing is the title. So basically what we are creating here we are giving the name of the title of the app. Then I'm writing here uh whatever the heading I want to keep right like welcome to my streamllet app. Then I have created a second input. So basically I am created an input that is st.ext input. So user can give. So here if I'll put it will ask me enter your name. If I'll give any input, whenever there is something like input, it will going to return it and it will say hello and whatever you have provided that in the input. Uh let me show you how it will look like uh uh with the demo and then uh we'll see how to access it right. So uh let me open the terminal. Now in order to run the streamllet ad basically you need two things. You need python. So I already have python installed in my system. Second you need stimullet package right? So let me create a requirements txt file and I can create a dependency here and I can write the package that I want. I'm not specifying the version here but then it's good to specify the version that you want. Right? So now if you see here I have two files app. py and requirement.txt. How to execute a stimulate app. Right? So first I need to install the package. So I'll run pip install r requirement.txt. txt and then okay uh that is something you can run it and you can see I already have the streamlet package so I don't have to uh do anything so it's already installed if you have installed it will ask you to install it and it will install it now let's run this app so I'll use trimlet to uh execute ute and run this file. So I this is the command that you have to pass. Trimlet run app. py. If you execute this, it is going to start the server and it is asking me to allow to run this app. Now you can see this app is running on my local host 8501. Let me go toward this port and you can see it my application is already up and running. And this is the simple app that I have built, right? Simple stimulate app. This is the heading that I have here. It is the uh text that is written. Welcome to your first streamllet app. If I'll give my name, let's say if I'll give Ashish Bob my name. Hey, hello Ashish. Right? Like it is just giving me back the name that I have. Right? So this is how simple it is to build a basic app that you really want to use it. Uh let me change it. Right? Uh let me get some more input. So I'll give it uh ask the name and uh date of birth and calculate age and use button to print the age right like I have just as basic functionality you can write it right so basically what I'm doing here I am using uh here two input I am going to take the name of the person I am going to uh get the date of birth of the person now based on that date of birth what I'm going to do I am going to calculate the age of the person and then it will say hey hello your age is this right please enter or if it is not p

Original Description

This comprehensive Docker tutorial is your ultimate guide to understanding and using Docker, from the fundamental concepts to a practical, hands-on project. We start by setting the context, explaining what Docker is and its real-world relevance. You'll learn about containerization, the key differences between VMs and containers, and why Docker is essential for solving issues like environment mismatch and bridging the gap between development and production. We'll then dive deep into the Docker architecture, including the Docker Engine, CLI, Daemon, images, containers, and volumes. You'll discover how Docker is used in real-life scenarios such as microservices, CI/CD pipelines, and ML pipelines. This video breaks down complex topics like Docker images, with their layered filesystem, and Dockerfiles, including key instructions like FROM, RUN, and CMD. We'll explore the full Docker lifecycle, from pulling images from Docker Hub to building, running, stopping, and pushing them. You'll also learn essential lifecycle management tasks like volume management and cleaning up resources. The tutorial culminates in a hands-on section where you'll set up and install Docker Desktop, pull a Python image from Docker Hub, and, most importantly, dockerize a Streamlit application from scratch. By the end, you'll have a solid foundation in Docker and practical experience to start using it in your own projects.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Analytics Vidhya · Analytics Vidhya · 0 of 60

← Previous Next →
1 The DataHour: Data Science in Retail
The DataHour: Data Science in Retail
Analytics Vidhya
2 The DataHour: Anomaly detection using NLP and Predictive Modeling
The DataHour: Anomaly detection using NLP and Predictive Modeling
Analytics Vidhya
3 The DataHour: Energy Data Science Project from Scratch
The DataHour: Energy Data Science Project from Scratch
Analytics Vidhya
4 The DataHour: Explainable AI Need and Implementation
The DataHour: Explainable AI Need and Implementation
Analytics Vidhya
5 The DataHour: Google Cloud AI/ML
The DataHour: Google Cloud AI/ML
Analytics Vidhya
6 Prediction to Production in Machine Learning #machinelearning #prediction
Prediction to Production in Machine Learning #machinelearning #prediction
Analytics Vidhya
7 Practical Applications of Data science in Ecommerce
Practical Applications of Data science in Ecommerce
Analytics Vidhya
8 How to tackle Overfitting?#machinelearning #overfitting
How to tackle Overfitting?#machinelearning #overfitting
Analytics Vidhya
9 Building Data Pipelines on GCP #googlecloud #datapipelines #data
Building Data Pipelines on GCP #googlecloud #datapipelines #data
Analytics Vidhya
10 Hands-on with A/B Testing #abtesting #datascience
Hands-on with A/B Testing #abtesting #datascience
Analytics Vidhya
11 Efficient Implementations of Transformers #transformers #cnn  #machinelearning
Efficient Implementations of Transformers #transformers #cnn #machinelearning
Analytics Vidhya
12 Modern Deep Learning Architecture #deeplearning  #architecture #deeplearningtutorial
Modern Deep Learning Architecture #deeplearning #architecture #deeplearningtutorial
Analytics Vidhya
13 Key steps for Designing Artificial Neural Network (ANN) for Image classification #machinelearning
Key steps for Designing Artificial Neural Network (ANN) for Image classification #machinelearning
Analytics Vidhya
14 5 things you should know about Azure SQL #azure #sql #datahour #datascience
5 things you should know about Azure SQL #azure #sql #datahour #datascience
Analytics Vidhya
15 AI & ML in the Automotive Industry #machinelearning #ai
AI & ML in the Automotive Industry #machinelearning #ai
Analytics Vidhya
16 Building Machine Learning Models in BigQuery
Building Machine Learning Models in BigQuery
Analytics Vidhya
17 NLP aspects in Telecommunication Industry
NLP aspects in Telecommunication Industry
Analytics Vidhya
18 Practical Time Series Analysis
Practical Time Series Analysis
Analytics Vidhya
19 Fundamentals of Quantum Computing
Fundamentals of Quantum Computing
Analytics Vidhya
20 A DAY IN THE LIFE of a Data Scientist (From waking up to working on algorithms)
A DAY IN THE LIFE of a Data Scientist (From waking up to working on algorithms)
Analytics Vidhya
21 Classification Machine Learning Model from Scratch
Classification Machine Learning Model from Scratch
Analytics Vidhya
22 Knowledge Graph Solutions using Neo4j
Knowledge Graph Solutions using Neo4j
Analytics Vidhya
23 Model Guesstimation (MLOps)
Model Guesstimation (MLOps)
Analytics Vidhya
24 ETL Pipelines in Google Cloud Platform
ETL Pipelines in Google Cloud Platform
Analytics Vidhya
25 Key steps for Designing Convolutional Neural Network(CNN) for Image Classification
Key steps for Designing Convolutional Neural Network(CNN) for Image Classification
Analytics Vidhya
26 Getting Started with AWS EC2 #amazon #aws
Getting Started with AWS EC2 #amazon #aws
Analytics Vidhya
27 How to Use Azure NLP and Graph Databases for Intelligent Knowledge Mining
How to Use Azure NLP and Graph Databases for Intelligent Knowledge Mining
Analytics Vidhya
28 Certified AI & ML BlackBelt Plus Program #shorts
Certified AI & ML BlackBelt Plus Program #shorts
Analytics Vidhya
29 Visualizing Data using Python #machinelearning #visualization #python
Visualizing Data using Python #machinelearning #visualization #python
Analytics Vidhya
30 DCNN for Machine RUL Prediction using Time-series Data #timeseries #machinelearning #datascience
DCNN for Machine RUL Prediction using Time-series Data #timeseries #machinelearning #datascience
Analytics Vidhya
31 M in ML stands for Math & Magic
M in ML stands for Math & Magic
Analytics Vidhya
32 An Unsupervised ML approach using Clustering
An Unsupervised ML approach using Clustering
Analytics Vidhya
33 Customizing Large Language Models GPT3 for Real-life Use Cases #gpt3 #datascience
Customizing Large Language Models GPT3 for Real-life Use Cases #gpt3 #datascience
Analytics Vidhya
34 Model Parameters vs Hyperparameters - Techniques in ML Engineering #machinelearning
Model Parameters vs Hyperparameters - Techniques in ML Engineering #machinelearning
Analytics Vidhya
35 Practical MLOps #mlops #datascience
Practical MLOps #mlops #datascience
Analytics Vidhya
36 Data Engineering with Databricks #dataengineering #databricks
Data Engineering with Databricks #dataengineering #databricks
Analytics Vidhya
37 Multi-Objective Optimisation
Multi-Objective Optimisation
Analytics Vidhya
38 When Airflow Meets Kubernetes
When Airflow Meets Kubernetes
Analytics Vidhya
39 AI in Banking
AI in Banking
Analytics Vidhya
40 Learn Convolutional Neural Network for Image Recognition
Learn Convolutional Neural Network for Image Recognition
Analytics Vidhya
41 Extracting Value from Data
Extracting Value from Data
Analytics Vidhya
42 How to measure Marketing Channel Effectiveness
How to measure Marketing Channel Effectiveness
Analytics Vidhya
43 Transforming Lives | Data Science Immersive Bootcamp
Transforming Lives | Data Science Immersive Bootcamp
Analytics Vidhya
44 Stock Market Analysis - AI driven approach
Stock Market Analysis - AI driven approach
Analytics Vidhya
45 Become a Data Engineering Professional in 2022 | Future Trends + Skills Required
Become a Data Engineering Professional in 2022 | Future Trends + Skills Required
Analytics Vidhya
46 Ensemble Techniques in Machine Learning #machinelearning #ensemble #datascience
Ensemble Techniques in Machine Learning #machinelearning #ensemble #datascience
Analytics Vidhya
47 The Power of Visualization | Tableau Full Course | Analytics Vidhya
The Power of Visualization | Tableau Full Course | Analytics Vidhya
Analytics Vidhya
48 Demand for Data Engineers is on the Rise | Data Engineer | Analytics Vidhya
Demand for Data Engineers is on the Rise | Data Engineer | Analytics Vidhya
Analytics Vidhya
49 Data Visualization in Data Science | DataHour | Analytics Vidhya
Data Visualization in Data Science | DataHour | Analytics Vidhya
Analytics Vidhya
50 Role of Optimization in Machine Learning & Deep Learning | DataHour | Analytics Vidhya
Role of Optimization in Machine Learning & Deep Learning | DataHour | Analytics Vidhya
Analytics Vidhya
51 Solving any Machine Learning Problem | Approach and Steps Involved
Solving any Machine Learning Problem | Approach and Steps Involved
Analytics Vidhya
52 Topic Modeling Explained with Implementation | Using LDA in Python | DataHour by Arpendu Ganguly
Topic Modeling Explained with Implementation | Using LDA in Python | DataHour by Arpendu Ganguly
Analytics Vidhya
53 Data Engineering in E-Commerce | The Best Case Study
Data Engineering in E-Commerce | The Best Case Study
Analytics Vidhya
54 Introduction to Classification using Azure Machine Learning | DataHour | Analytics Vidhya
Introduction to Classification using Azure Machine Learning | DataHour | Analytics Vidhya
Analytics Vidhya
55 Introduction to Federated Learning | DataHour | Analytics Vidhya
Introduction to Federated Learning | DataHour | Analytics Vidhya
Analytics Vidhya
56 Diffusion Models for Generative Arts | DataHour | Analytics Vidhya
Diffusion Models for Generative Arts | DataHour | Analytics Vidhya
Analytics Vidhya
57 Master Google Analytics in 1 Hour | DataHour | Analytics Vidhya
Master Google Analytics in 1 Hour | DataHour | Analytics Vidhya
Analytics Vidhya
58 Learn Hypothesis Testing | DataHour | Analytics Vidhya
Learn Hypothesis Testing | DataHour | Analytics Vidhya
Analytics Vidhya
59 A Practical Approach to Kaggle Competition | DataHour | Analytics Vidhya
A Practical Approach to Kaggle Competition | DataHour | Analytics Vidhya
Analytics Vidhya
60 Making AI work for Business | DataHour | Analytics Vidhya
Making AI work for Business | DataHour | Analytics Vidhya
Analytics Vidhya

This video tutorial provides a comprehensive introduction to Docker, covering the basics of containerization, deployment, and orchestration, and providing hands-on experience with building and running Docker containers and images. By the end of this tutorial, viewers will be able to design and deploy distributed systems using Docker.

Key Takeaways
  1. Build a Docker image based on another image with additional customization
  2. Create a new image by modifying an existing image
  3. Pull an image from the Docker Hub or a registry
  4. Push an image to the Docker Hub or a registry
  5. Create, start, stop, or delete a Docker container using the Docker API
  6. Build a Docker image using the Docker build command and a Dockerfile
  7. Run a Docker image using the Docker run command and define the port and image name
  8. Copy files from the local file system to the Docker container using the copy command
  9. Define the default program to run in a Docker container using the cmd command
  10. Build a Docker image using a Docker file
💡 Docker provides a platform for building, shipping, and running applications, and allows for faster deployment and scaling of applications.

Related Reads

📰
Catching Rogue Hex Codes in CI Before They Reach Production
Learn to catch rogue hex codes in CI before they reach production to ensure consistent design and branding
Dev.to · Alexander
📰
Thinking Like a Platform Engineer: Celery, Docker, CI/CD, and Getting SokoFlow Into the Cloud
Learn how to design a scalable platform using Celery, Docker, and CI/CD pipelines to deploy SokoFlow to the cloud
Dev.to · Kirera paul murithi
📰
Dagster AuthKit v0.4.0 - Security Hardening, Cross-Pod Sessions, and We Need Your Help
Learn about Dagster AuthKit v0.4.0 and its new security features, including cross-pod sessions, and how to contribute to its development
Dev.to · Demetrius Albuquerque
📰
Automating Linux Tasks with Bash
Automate repetitive Linux tasks using Bash to boost productivity
Dev.to · Adeje Oluwatobiloba
Up next
How to Code with Distrobox on the Steam Deck
Ian Wootten
Watch →