Docker Tutorial for Beginners | Full Course [2021]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys welcome to amigos code in this full docker tutorial i'm going to teach you everything you need to know about docker this course is designed for beginners to take you through docker and then fully grasp docker so this is everything that you will need in order to start using docker docker is so popular and you must have it on your cv in this course i'm going to make sure that you understand what docker is the difference between docker and virtual machines then we're going to move on into understanding what containers are exposing ports understand the useful commands that docker has to run moving on i'm going to show you how to take two applications one website as well as an api build with express js and then we're going to write a docker file to package it up so that we can run multiple containers so this course will be so practical that you will learn a lot in this course i'm also going to teach you about the best practices when it comes to docker how to properly create your docker files by using layering and caching effectively i'm also going to teach you how to tag your applications meaning that you can have multiple versions of your application and then allow you to choose between which one that you want to run we're going to learn how to debug ie how to bash into containers so we know what is going on how to inspect logs and a bunch more if you need to my channel go ahead and subscribe give me a thumbs up so i can keep on recording these videos also if you're not part of the amigos code community i would love to have you there because the community is growing without further ado let's go ahead and learn about docker right one quick thing that i want to mention and that is please do practice as i teach like i don't want you just to sit there and watch this course and do nothing because i'm going to gain real value of this course so as i type go ahead and type and experiment if you get errors or there is something that you know quite understanding just post them on a group or comment down below in this video and we will get back to you so i really want to add value so by the end of this course you should have a complete understanding of what docker is and you can have it on your cv also if you want to take this course at your own pace and then receive a certificate go ahead and enroll to the exact same course on my website that way you get a certificate so that you can show to employers this is all for now again if you haven't joined the private facebook group as well as discord go ahead and join now and without further ado let's kick off this course all right let's go ahead and understand what exactly is darker so docker is a tool for running application in an isolated environment so it's very similar to a virtual machine but it's much faster and doesn't require a lot of memory and an entire operating system to operate the cool thing about docker is that your app runs in the exact same environment if it works on my machine it will definitely work on your machine if it works on the staging environment it will also work in the production environment so this is one of the benefits of docker and pretty much it just works right if it works by machine then you are guaranteed that whatever you deploy your application it will also work and docker nowadays is the standard for software deployment pretty much everyone is adopting docker in their workflow for software deployment because it makes it easier for packaging applications you don't have to deal with different os different distributions and pretty much whatever you package will work in production so pretty much almost every company is adopting docker and you should be aware of how to use this tool as well so what exactly is the difference between containers and virtual machines so a container is an abstraction at the app layer that packages your code and dependencies together multiple containers can run on the same machine and share the os kernel with other containers and each running as an isolated process in user space so this is very important because a container doesn't require a full operating system and it simply shares the underlying operating system but running in isolation of other containers in contrast with virtual machines is an abstraction of physical hardware turning one server into many servers the hypervisor allows multiple vms to run on a single machine each includes a full copy of an operating system this is very important a full copy of an operating system also the application necessary binaries and libraries taking up tens of gigabytes and also they are very slow to boot so just let me show you exactly a visual diagram so this is a containerized application so you can see that you have multiple apps underneath you have docker and nothing else so docker manages all of the containers that you spin up and underneath docker you have the host operating system and then you have the actual infrastructure in contrast with a virtual machine you can see that you have the infrastructure on top of that you have the hypervisor and this allows one server to be turned into multiple servers and you can see that each virtual machine requires a full guest operating system so this is the fundamental difference between docker and virtual machines so the benefits of using docker is that you can run a container in seconds instead of minutes as you see that for you to spin up a full operating system it takes a while also less resources results in less disk space as well as less memory so these are very good advantages of using docker instead of virtual machine and as i mentioned you don't need a full operating system so these are some of the advantages of using docker but obviously you have things such as deployment and testing so you can test things locally and then you can take it to whatever environment and it is absolutely guaranteed to work if you have any questions go ahead and drop me a message otherwise let's move on and learn how to install docker all right let's go ahead and learn exactly how to download and install docker navigate to docs.docker.com forward slash install so right here you can see that you can download docker for linux macos and windows so the process is the exact same thing whether you are on windows or mac so because i'm on a mac let me go ahead and show you exactly how to get it for mac but for windows is the exact same thing i'm going to show you in a second so go ahead and click on mac os and then you can see that to download docker for mac head to docker.hub so what i'm going to do is press command and click on the link and then right here you can see that i can get started with docker so what i need to do first so to download docker desktop so this is what we need is to pretty much create an account or sign in and once you have the account you will be able to install docker the process is very straightforward so you can see the requirements so mac os sierra 10.12 or above so if you are using a previous version you need to download docker toolbox so docker toolbox is the old way of using docker and docker desktop is the newest and better way of working with docker so let me go ahead and pretty much show you exactly how it works or actually how it's downloaded so you can see that they have a screenshot so basically once you have an account then you'll be able to download docker so basically you take this docker dot app put it into your applications and then you'll see that you have docker and then at the very top on your toolbar you can see that you'll get a docker logo so this logo right here and you can see that it will say docker is up and running and you can see right here in my machine because i already have docker installed you can see that docker is up and running so it's very straightforward to get started with docker so for windows it's pretty much the same thing so what i'm going to do is collapse this click on windows install docker on windows and you can see that it's the exact same thing so download from docker hub there we go is the exact same thing so please log into download and then once you have it downloaded you can follow these instructions right here but basically it's the exact same thing here so if i scroll down you can see that you have docker for windows you will also get the actual docker logo and then you'll see that docker is now up and running which is the exact same thing that i have here so go ahead and download docker desktop for whatever operating system that you are using and if you have any questions or if you get stuck go ahead and drop me a message but this should be very straightforward in the meantime join me in the next one now that we have docker installed go ahead and click on this docker logo icon at the very top and you can see that we have a couple of options right here so we have preferences updates documentation more of docker sign-in and kubernetes so what i'm going to do first is to open up your terminal or command line and simply type docker and you should see that you get a bunch of commands so you can see that you get a bunch of stuff really so options and then management commands and you can see all of these commands that we will learn in this course so you saw that you can type docker but also if i go ahead and type docker dash dash and then version you can see that this is the version of docker that i have installed on my machine this might be a bit different for you but the commands will be the exact same thing so what i want you to bear in mind is that if i click on the docker logo again and then quit docker desktop and then type docker and for now simply go ahead and type docker ps you can see that cannot connect to docker daemon right here so the docker demon is not running so whenever you are using docker make sure that the actual docker demon is running so let me go ahead and simply run it again and let me skip this version and you can see that it's starting just give it a second you can see that it's starting right here and there we go you can see that it's green if i now go back to terminal and type docker ps you can see that this time it works right so just to bear in mind that whenever you want to use docker you have to make sure that the docker daemon is running and there you go you now have successfully installed docker and know how to get it apparently let's begin our journey in learning docker let's begin our journey learning this awesome technology called docker all right let's go ahead and learn about darker images and containers so an image is a template for creating an environment of your choice this could be a database a web application an app that does some processing pretty much it could be anything an image is also a snapshot and you'll learn more about this basically you can create multiple snapshots i.e versions of your image and then you can point to whatever version that you want at a particular time so let's say that you deploy to production and image you find out an error and what you can do is simply go back to the previous image what is so special about an image is that it contains everything your app needs to run it contains the operating system any software required as well as the application code so once you have an image then containers come into play so a container is simply a running instance of an image so what you do first is you have an image and then from that image you simply run a container let's go ahead and download an existing image and run a container from it all right let's go ahead and pull an image and run a container from it so navigate to hub.docker.com and right here you can see a list of all public images so right here so you can see that if i scroll down you have a list of official images so these are companies for example such as nginx node redis ubuntu couch base a golang so there are tons of these official images that we can use but also there are some unofficial images so these would be for example someone like yourself or i that don't necessarily own a large company but we just build images for other developers to use so we could also distribute these images inside of this docker registry so docker hub is simply a registry and we're going to learn more about registries later on but a registry is simply a place where you can download images so you can see that i can explore some images so let me go ahead and simply explore and you can see that there are tons of these images right so i can scroll down and and the list is endless so the one that i want to try out with you is this one nginx so what i'm going to do is if you don't see this image right here so nginx so scroll up and right here simply type n g next so and i always get this one so nginx nginx just like that so i always get this name wrong so enginex is simply a web server a reverse proxy a load balancer and it's very popular and it's used all over the internet so if i scroll down you can see that they have some tags and we're going to learn about tags later on docker file as well later on we'll learn about this and they have some quick reference so what is nginx and how to use this image so let's actually scroll up and you can see that they have this command right here so docker pull and then nginx and let's go ahead and pull this image so let me go ahead and open up terminal or you can use command line if you are on windows so let's simply go ahead and say docker and then pull and then ng and then x just like that and then press enter and you can see that it's using a default tag and it's actually downloading nginx for us so just give it a second and i'm going to explain all of this later on but basically if this image changes it doesn't have to download every single layer again so it is cached there we go and you can see that it has downloaded a newer image for nginx and then column latest so this part right here is the actual tag and we're going to learn about tags later on but basically this is simply getting the latest image now in order for us to see a list of images that we have locally simply go ahead and type docker and then images and there we go so you can see that the image that we have currently is this one so we only have one image and the name is nginx the tag is latest this is the image id and you can see that it was created about three days ago and the size is 109 megabytes there you go you successfully managed to pull your very first docker image next let's go ahead and run a container from this image all right let's go ahead and run a container from this image that we've just downloaded so nginx and then the tag is latest so remember a container is a running instance of an image so to run a container from an image simply type docker and then run and then we have to specify the actual image so in our case will be nginx and then you have to specify the tag so in our case latest so if i press enter you can see that we get nothing so believe me or not but we are actually running a container so the reason why this is hanging because the process has started and is just waiting so what i'm going to do is open up a new tab and inside of this tab what i'm going to do is first let me actually make this bigger and so something like that so you can see exactly what we're doing so what i'm going to do now is describe the list of all running containers to do that simply type docker and then container and then ls press enter you can see that we have this container with an id of eight three nine one zero abd three six zero c and then the image is nginx latest you can see some commands created about a minute ago the status is up about a minute and you can see that the ports it's 80 so 80 i'm gonna explain the poor in a second and the name is hap evil heart so i might explain this bit in a second so this port right here because it's very important for us but you can see that we have an image up and running so go back to the other tab and you can see that right here so this is actually a bit bigger now basically the process is hanging right here so what i'm going to do is simply cancel out of this so ctrl c there we go i'm going to click screen there and right here simply type docker container and then ls and you can see that the container is no longer up and running so the same here so remember this was a container so docker container ls you can see that nothing is up and running so what i'm going to do now is close this tab and i'm going to run the container so docker run nginx latest but now what i'm going to do is add a flag so minus and then d so this simply says run this container in detached mode so if i press enter you can see that the process is no longer hanging so it's running in detached mode and then we get this id right here so now we can view the list of all containers running so docker and then container and then ls enter you can see that this is our container which is up and running 18 seconds ago so let me go ahead and clear the screen another way that you can check the list of running containers is simply type docker and nps so this is the preferred way and much faster enter and you can see that we get the same thing and now you can see everything is the same apart from the actual name right here so suspicious snyder and the poor is the same so this part right here i'm going to explain next but this is very important for us to understand so 80 and then tcp and there we go so you successfully managed to run your very first container by running docker run minus d in detached mode and then the name of the actual container so nginx column and then latest next let's go ahead and learn exactly how we're going to be able to use the container let's go ahead and learn about how to expose ports with docker so so far we have our host which has docker running so we are running docker in our computer and right now we have one single container which is running nginx and this container is exposing a tcp port and the port is 80. so let me show you exactly this again so right here you can see that we have ports and then 80 and then forward slash tcp so what we want to be able to do is from the host we want to issue a request to our container which is exposing port 80. so we want to be able to go to our web browser type localhost 8080 and then that port 8080 should be mapped to port 80 on the container so basically we want to go from the host to the container and the way that we achieve this is simply by adding dash p before we run the container so dash p 8080 from the host should be mapped on port 80 on the container and then we'll be able to access the application running from within the container so let's go ahead and open up terminal or command line and what i'm going to do first is stop this container so to stop a container simply type docker and then stop and then pass the container id so i'm going to come and see that command v and then enter and you can see that the container has topped so if i type docker ps you can see that nothing is running let me clear the screen so i'm going to issue the same command so docker run minus d or dash d and then let's go ahead and say dash and then p and we want to go from the host so whenever we type localhost 8080 we want that to be mapped to port 80 on the container so press enter and you can see that the container is up and running docker ps and there we go so now you can see that the ports is a bit different so you can see that right here we are simply saying map localhost 8080 to port 80 inside of the container now let's go ahead and open up anywhere browser and then simply type localhost and then column 8080 and then enter and there you go so you can see that we have this welcome page that says welcome to nginx and there we go so we've managed to map the host port 8080 to the container port 80. so let me go ahead and pretty much just stop this container so darker and then stop and then pretty much just get the id there we go if i now refresh you can see that the site can't be reached so we've mapped port 8080 but you could also map a different port so let's go ahead and map port 3000 there we go now if i change this to port 3000 and you can see that it's working but from a different port we could also map both port 8080 and port 3000 to pour 80 inside of the container so let's go ahead and do that so let me go ahead and simply stop the container so i think this will be now a different container so let me go ahead and simply say docker and then ps grab the id docker stop there we go clear the screen ctrl l now if you want to map more than one port simply add another dash p 8080 to port 80. enter now if i type docker ps you can see that right here localhost 3000 maps to port 80 inside of the container and localhost 8080 also maps to port 80 inside of the container so let's go ahead and test this out so if i refresh this should work so 3000 works and now 8080 and this also works there we go you now know how to map ports from the host to containers if you have any questions go ahead and drop me a message otherwise let's move on let's go ahead and learn exactly how to stop remove start and name containers so if i go ahead and type docker ps you can see that currently we have this container right here so this is the id and it's mapping both port 3000 and 8080 to 80 inside of the container so this is what we have currently right so this is the nginx localhost 8080 this works and localhost 3000 this works so the way that you stop containers is simply by saying docker and then stop and then you can pass the id or the actual name so let's go ahead and grab this name right here so command c paste that in and then enter and you can see that we get the name back now if i check my web browser refresh you can see that it's not working because we stopped the container now an interesting thing is we've just stopped the container but we haven't removed it so the container still available for us to start so to start the container simply grab the same name and say docker start and then the same name or the actual container id enter you can see that i get the name back if i check my web browser and there we go so you can see that the page is working again now let me go ahead and stop this container says docker stop and this time i pass the actual id and let me clear the screen for now refresh the web browser you can see that it's not working if i go back so how do you know the list of containers that are not running so if i type docker bs you can see that we have no containers right here but indeed what this command does so docker ps it simply lists the running containers so go ahead and type docker and then ps dash dash help right here you can see that you can pass some options so dash a for all and you can see that the default shows just running and you can do some filtering you can do quiet that displays only the numeric ids and you can check the size as well so let me go ahead and simply clear the screen and type docker ps dash and then a and you can see that we have a couple of containers right here and all of them are nginx so remember up to now we've actually stopped many containers and then we start them again and whenever we start them we simply got a different name so you can see that this is a different name this is a different name the same here and also the id right we get a brand new container so we've never reused existing containers now how do we delete containers right so how do we delete containers so to delete a container so what you need to do is simply say docker and then rm and now you can delete a container by the actual name or container id so let's grab this very first one right here created 25 minutes ago and you can see the name is elastic sanderson paste that in enter we get the actual container back now if i type darker and then ps minus a you can see that the container is gone so if i remove that and remember uh i've actually searched before so this is the actual id that we removed and you can see that it's no longer in this list so just let me cancel out of that you could also remove every single container in one single command so you could say docker rm and then you could say i want to delete that one and then you'd say i want to delete this one as well so docker rm but you can see that it's a bit tedious so what we can do is grab every single id and then pass that into a command and then we will delete everything so the way we do it is simply so if i click screen so docker ps dash dash help you can see that we have this quiet so display only numeric ids so let's go ahead and say docker ps dash and then a meaning that i want every single container including the ones which are stopped and then q for quiet that gives me only the numeric ids if i press enter you can see that i've got only five so if i want to remove all of these i simply type the docker and then rm and then press dollar sign and within dollar sign simply say docker bs minus a and then q right so we're simply getting this command and passing it inside here and this will remove every single container that we have now bear in mind that if you have a container that is running this won't work so let just let me first delete and then you'll see it so if i remove everything you can see that i get every single id back now if i type docker bs minus a you can see that we have no containers available now let me go ahead and start a container so if i click screen so let me search here so 3000 and let me go ahead and start this container there we go talker ps you can see that it's running if i refresh the browser there we go now if i go ahead and simply uh try and remove the container right so let's go ahead and run this exact same command so docker rm and then give me all the containers so if i press enter it says that you cannot remove a running container and stop the container before attempting removal or you can do a force rm so the way that force rm works so you simply pass dash f and it simply says that i really don't care whether it's running i simply want to remove the container and that's it so if i press enter you can see that that took a while and i get the id back so if i refresh the page you can see that we have no containers now if i do a docker ps and there we go darker bs minus a enter and we have no containers available if you have any questions on stopping starting and removing containers go ahead and drop me a message next let's go ahead and learn how to name containers all right let's go ahead and start a container so simply type docker run minus d minus p and then expose whatever ports that you want and then press enter so if i type docker ps you can see that we have a name right here so elegant and then right so usually this is a random name that is given to you if you don't specify a name but in reality when you create your own containers you should be giving them a name so that you don't rely on the id nor the actual random name right so the way that you give a name to a container is simply by using dash dash and then name so let's go ahead and simply stop this container so docker um actually let's go ahead and force and remove everything so docker rm dash f docker ps and then dash aq enter there we go so now let's go ahead and run the exact same command so docker run minus d so what i'm going to do is go to the start and then right here simply go ahead and type dash dash and then name and now we can give this a name so let's go ahead and simply say that this will be our website right so now if i press enter you can see that the container is running but if we type docker ps you can see that now the name is website and this makes your life much easier for you to identify your containers and trust me you should always name your containers because most likely you'll be running multiple containers at the same time so now i can simply go ahead and say docker stop and then website and you can see that i don't have to rely on the actual container id i could use it but because i've named my container i can simply say stop my website just like that so if i press enter you can see that stopped the website and i can simply start it again so docker start and then website so there we go you now know how to name containers all right let's go ahead and learn exactly how we're going to take a docker ps and format this result right here so you can see that sometimes it might be a bit difficult for you to read what's going on so you can see that we have container id and then the id it's right here and then we have the status and the status goes over to the next line and then we have the image and you can see that the ports then it's yeah sometimes it's very difficult for you to read let's actually go ahead and start a second container so darker and then run and then minus d minus b and then nginx and then latest and let me actually name this so that dash name and then web site and then two and the port as well so let's go ahead and simply map that 9000 to port 80. so press enter you can see that it's running so if i do a darker ps now you can see that i've got two containers up and running and the output is a bit it's even harder to read actually so what we can do is simply use a format so we can say docker ps and then minus minus format and this is equal to and what i'm going to do is simply copy some code right here but basically this simply um gives a label and then tab and then right here it grabs the actual id the same with name and then names image and then image port so on and so forth and you can get this entire line in the description of this video so let me go ahead and simply command c go back and what i'm going to do is simply paste that in and this has to be within quotes and if i now press enter you can see that now the format is much nicer so you can see that we have the id the name image for command created status and basically it's much easier for you to read if you don't have enough room so what i like to do with this is simply export to a variable so format equals two and then paste that again oh actually i need to paste this again so copy and then paste that enter and now if i type docker ps you can see that it's not formatted and if i type docker ps dash dash and then format equals to dollar sign and in format so this is the name of the variable so this dollar sign format refers to this variable right here so if i press enter and let me do that again so you can see exactly nice and neat and there we go so you can see that it's formatted and there we go you now know how to format the results of docker ps all right in this section let's go ahead and learn about docker volumes so docker volumes allows us to share data this could be files or folders so you can see on the diagram that i have here that you have a container and then you have the file system and under that you have the darker area and through the container and the file system you create a volume so i'm going to show you exactly this in a second how it works but volume simply allows us to share data between host and container and also between containers so the way it works is that you have a container running on a host and in our case we have an nginx container so one we have to create the volume and then this volume allows you to share data between the host and container and vice versa so let's say that we add a file in our host in our machine this file a will also appear in the actual container inside of the volume the same by adding a file in the actual volume inside of the container that will also appear in my host operating system and the same is true with folders so if you add a folder on your host then that will also appear in the actual container let's go ahead and learn exactly how to share data between host and container all right so go ahead and navigate to hub.docker.com and search for nginx and right here what i want to show you is exactly how we're going to be able to serve our own files during development with nginx so scroll down and right here you can see that hosting some simple static content and basically you can see that right here so they give a name to this container so some engine x and then dash v and then this is the actual volume so this bit right here is the source and this is a destination so inside of the container so this path right here so user share nginx and then html inside of that folder we can share our own files and if you are developing an application or a website that's where you should put your files in and then right here you can see that this is a read only volume so let's go ahead and pretty much create a file and then mount our directory inside of this folder so that we can override the default nginx welcome page so let me go ahead and open up terminal and docker run and then dash dash name let's go ahead and create a website so i've deleted all the previous containers and dash p and then 8080 to 80 and then the actual um container will be n g n x and i can say dot latest or if i don't specify the actual tag it will bring the latest by default so if i run this or actually let me actually add a dash d for detached and then if i go to my web browser refresh you can see that's forbidden and this is because this is 8080 and there we go we have this default nginx welcome page in the next video let's go ahead and override this default webpage by simply mounting a volume from the host to the container right let's go ahead and create a volume between our host and our container so inside of our desktop so in the host machine we will create a folder called website and then we're going to have an index.html so that file or the contents inside of the website folder will be shared inside of the container in the following directory so users share nginx and then html so that way when we hit the url in our web browser we will be saved with our own files so let's go ahead and do that now so right here what i'm going to do is pretty much just open up vs code and go ahead and open up your favorite ide but in my case i'm going to open up vs code and then what i'm going to do is simply create a new file and then in this file let's simply go ahead and have an h1 so this will be some html so h1 and then hello docker and volumes so we will have a better page but for now this will be enough so now go ahead and save this navigate to desktop inside create new folder name this as a website and then create and then name this as index.html press enter and there we go now what i'm going to do is start a container and mount the website folder to our container so go ahead and open up terminal and right here let me simply say docker and then stop and then website there we go docker rm and then web and then site there we go so this is completely removed so now let's go ahead and navigate to the website folder so cd and then desktop and there we go and also cd into website so if i do an ls you can see that we have index.html now let's go ahead and start a container and then mount the entire folder to our container so the way we do it is let's go ahead and scroll up we'll actually go up a couple of times and now what we're gonna do is so pretty much off the website so after you name the container go ahead and simply say dash and then v and then right here we can simply say dollar sign and then within brackets pwd so this simply takes uh the present working directory so let me actually show you so let me cancel out of that if i type pwd i get the content so this is what i get right so if i pass that so i think on windows you simply say dir and you get the same thing so let's go ahead and grab this again and then what we're going to do is we're going to mount this folder called website 2 and remember so if i open up nginx you can see that this is the actual destination so user share nginx html and then you can say read only so grab everything and then go back and then paste that in and there we go so now let's go ahead and press enter and there we go you can see that we have started a container and if i now go to my web browser and then remember before we had this welcome page which was the default presented by nginx now if i refresh you can see that we are serving our index.html so let's go ahead and change that so let me go ahead and simply say hello with volumes and then let's simply say read and then only save this go back refresh and you can see that the contents are mounted right so whenever we change the index.html that is reflected in our container so what i'm going to do now is i want to show you that if we have a file inside of the container that will also appear in our host so go ahead and simply type this docker and then exec and then dash i t and then simply say web site and then bash so this this simply says that we want to execute this in interactive mode pass the actual um container and then we want to execute the bash command so if i press enter you can see that now we are inside of the container so if i if i type ls dash al you can see that this is the linux file structure inside of our container so remember this is the running container so now remember we mounted so user share nginx html so let's go ahead and navigate to that so cd and then user share engine x html and then if i click the screen if i do an la or actually ls al you can see that we have our index.html now let's go ahead and simply say touch and then about dot html and this is just a file with nothing inside so if i press enter you can see that this is a read only volume which means that the container can only read the contents if he wants to add if he wants to write to it it's impossible so the way that you tackle that so let's go ahead and exit this container so control and then d and then docker ps let's go ahead and simply say docker rm dash f and then website there we go now what i'm going to do is simply run the exact same uh container but right here instead of passing the read only flag i'm going to remove that enter now let's go ahead and bash into the container again so docker exec dash i t website and then bash enter cd to user and then share nginx html if i click the screen now if i do an ls you can see that we have index.html if i touch about dot html press enter you can see that works now if i go to my desktop and you can see that we have this folder right here called website so i'm going to open it up and you can see that we have the about.html right here so from our container this file also appears in our host and you can see that this still works and there you go this is how you share files between the host and containers using volumes if you have any questions go ahead and drop me a message otherwise join me in the next video all right let's go ahead and customize our website so this website right here which simply says hello docker and volumes and by the way that's not read only anymore so let me go ahead and remove that and if i visit the page again refresh you can see that hello docker and volumes so go ahead and navigate to google and do a search on bootstrap single page template so go ahead and click on this very first link so free bootstrap for landing page themes and right here go ahead and pick any website of your choice so what i'm going to do is pretty much just pick this one right here so grayscale and then click on view on github there we go so now let's go ahead and simply clone or download let's go ahead and download the zip now open this in your desktop and then let me unzip this there we go delete the zip and what i'm going to do is pretty much just take everything so i'm going to take everything here command c and then go to my website and then let's delete everything and then paste there we go so you can see that we have this index.html and we can go ahead and delete this folder so bootstrap grayscale master delete that and there we go so now i'm inside of the container so i'm going to do an ls minus al you can see that we have the files that we've just downloaded so what i'm going to do now is simply visit the web page so i'm going to close this and this as well and go ahead to localhost 8080 before we had hello docker and volumes now if i refresh you can see that we have this awesome website and feel free to make changes to this website according to your needs so you can see that this works beautifully right so you can see that we have a nice beautiful website so i can click on projects you can see that takes me to projects contact and there we go right so let me go in about and you can see that it's filled with bootstrap and you can see that it's working beautifully and there we go i just wanted to show you that you don't have to have a boring website as we had so you can go ahead and build your own website and then deploy it with nginx all right now let's go ahead and learn how to share volumes between containers so we have a container a and we have a container b and we can share a volume between them i.e we can share the contents of a folder or a file between these two containers so let's go ahead and try that out so currently we have this nginx container named website and it's serving our beautiful website so you can see that running on localhost 8080. the way that we can share files or folders between containers is by using a command volumes from so go ahead and type docker run dash dash help and this give and this will give you all the options that you can use with docker run enter and you can see that at the very bottom you have volumes from so dash dash volumes from and then mount volumes from the specified container so let's go ahead and clear this and then docker ps so let's go ahead and start a brand new container so docker run and then dash dash name let's go ahead and call website dash copy and then dash and then d minus and then p so this will be 80 81 to 80 so 480 is already being used so we have to map to a different port and then go ahead and simply say n g and then x and right here what we need to do is simply say volumes right because we want to map a volume from this running container so the way you do it is dash dash volumes dash and then from and then you pass the actual name so the name of the container is website now let's go ahead and press enter and you can see that it's up and running darker actually let me press up two times clear the screen you can see that we have two containers running one container is available through 8081 so that's the port and this is the website copy and the website is through our 8080 port so let's go ahead and give that a go so open up your web browser so 8080 so this is the main website so refresh you can see you can see that this still works now if i go ahead and hit the 8081 which is the website copy container and we shared all the contents from the website container to the website copy container this container should have the exact same website so if i press enter you can see that still works so we've managed to share data across these two containers all right in this section let's go ahead and learn exactly how to use docker file to build our own images so far we've been using existing images ie the nginx image and from that we've been running containers so what a docker file allows us to do it allows us to create our own images by creating a file called docker file and this file simply contains a list of steps of how to create images and then we can run images built from docker files as we've been running existing images let me go ahead and show you the documentation that you need when building docker images all right so right here this is the docker file reference so in this page you can find every single command that you can use when building images so as i mentioned before docker file it's simply a series of steps that defines how your image is built so in this page right here you can see that they have quite a lot of things but if i scroll down you can see that they have um you know stuff with environment replacement docker ignore and then from keyword so every single docker file has to have this from um keywords i'm going to explain this in a second and then you have the run command and then you have the cmd command you've got label you've got expose you've got add you've got copy entry point you've got args you've got a bunch of these commands that allows you to build docker images let's go ahead and create our very first docker file and then create an image from it all right let's go ahead and take this beautiful website and build an image using a docker file and then we can pretty much run as many containers that we want from our custom image so far we've been mounting a volume so if i show exactly what what we've been doing so right here in this command so we've been mounting a volume from the host to the container so this is why you can see this beautiful website so so we are taking all the index or html all the javascript pretty much so if i do an ls here or actually ll so you can see that we have a bunch of things so we have css images js vendor so basically we have everything and then we mount a volume inside the container and then we are able to view this awesome website like this so this is really good for development purposes so you want to mount the volume when you are doing uh stuff in development but when you want to build a custom image you don't need to mount a volume from your host to the actual container so what you ought to do is to copy so you want to copy everything everything into your image right so when you're actually defining how you want to create an image you ought to copy this so that you don't have to mount a volume so let's go ahead and learn exactly how to do that and then run a container from it so what i'm going to do here so i'm going to pretty much just say darker and then let me clear that so i just press ctrl l image and then ls and you can see that we have the nginx image so this is the latest tag and that's the one that we've been using so far and i've gone ahead and deleted all the previous containers and i'm only left with one container which is running our website so docker ps watch let me format this so like that so you can see that so that and that so you can see that we have one image and we also have one container which is running based off this image so what we want to do now is create our custom image and then run a container from it so right here we don't need to mount a volume anymore if we are building our own image that contains everything and remember images should contain everything that your application needs to run so it should contain all the dependencies all the source code pretty much everything that your application needs to run and that's what we're going to do now so go ahead and open up vs code or any ide and open up the website folder so inside of this website folder let's go ahead and create a docker and then file so this must be named as dockerfile and make sure that this is inside of the root folder so inside of the website folder so right here the very first command that we're going to learn is the from keyword so from keyword is the name of the base image that we want to use so usually when you build your own images you will never build an image from scratch you will always use an existing image as your base image and then produce your own image so in our case we want to use the nginx and then column and then latest so you've seen this already so when we say docker run we're running this image right here so we want to build an image based off this image right here so this image called nginx now the second command that we're going to do is we're going to say add so let's go ahead and say add and then simply say dot and then we want to add everything in the current directory so css image javascript pretty much everything right here into a destination and if you remember correctly so the destination that we want to add is this one right here right so this is where the static content should live if you want to serve static content with nginx so let me go ahead and simply paste that in so this is from and then this is the actual destination and let me go ahead and save this and this is pretty much a very simple docker file that will produce an image now that we have a docker file next let's go ahead and learn how we're going to build an image from this docker file all right now that we have our docker file now let's go ahead and build an image from it so go ahead and open up terminal or command line if you're on windows and make sure to navigate to the website so right here if i do an ls or actually la you can see that i have my docker file right here so the way that we build images from docker file it's simply by running this command so we need to say docker and then build so we want to build and we have to specify few parameters so at least we must specify the tagging so how we want to tag this image so go ahead and simply say dash dash tag or simply dash and then t so let me go ahead and say dash dash and then tag and in fact let me show you the commands so docker build and then dash dash help so here you can see the list of all the commands that you can use when building from a docker file so right here so this is the one so dash t or dash dash tag so name and optionally a tag in the name and then the actual tag so this is the format right so let's go ahead and simply clear this so let's go ahead and say docker and then build and then dash and then dash tag so that you remember that dash t is dash dash tag and then let's go ahead and give it a name so the most obvious name is website and then right here let's simply go ahead and give this a tag so the tag will be latest and i'm going to show you exactly the best way of you tagging your images later on but for now let's simply go ahead and say that the name right so when you tag you say that the first bar is the name so the name is website and then the version is latest so the same way that you saw with nginx so if i cancel out of this for now so docker and then image and then ls so right here you can see that the name is nginx and then the tag is latest in the way that we refer to it is simply saying n and then genex and then column latest so we are doing the same thing for our own image so let's go ahead so let me go ahead and simply grab this and then clear the screen ctrl l paste that in and then the last thing that you have to specify is where is your docker file so my docker file is inside of this directory called website so simply go ahead and add a dot so this will look for a docker file and then build an image from it now let's go ahead and press enter and you can see that we have built an image so you can see that right here we had two steps so the from so this is the actual um line one right here so so this is the base image and then you can see that we have the step two which simply added everything in the current directory to this destination inside of our container and you can see that we have some random numbers here and i'm going to explain this in a second and you can see that we built an image and we successfully tagged it as a website and then latest now if i go ahead and simply say docker image and then ls and now you can see that we have two images and this is our image so you can see that the repository is website the tag is latest the image id so this is the image id which is this one right here and you can see that it was created about a minute ago and then the size of it is 135 megabytes so there we go now that we have an image let's go ahead and run a container from it so let me go ahead and click screen and do a docker ps format and let me go ahead and simply stop this container so darker or in fact let me go ahead and remove this container so docker rm and then dash f and then web site there we go you can see that we have uh no containers running there we go everything is empty and let me actually see if we have any containers which are currently stopped so docker ps dash a and then you can see that everything is empty that's fine now let's go ahead and pretty much just do a docker and then image ls and let's run a container based off this image right here called website so let's go ahead and simply say docker and then run dash dash name let's give it a name website and then right here let's simply say dash p for the port so this will be 8080 from the host to port 80 inside of the container and then let's go ahead and also say that we want to run this in detached mode so dash d or minus d and finally the image that we want is website and then column latest and if i go ahead and press enter you can see that we get this huge id back if i do a docker ps you can see that we have a container running and it's running our own image so the the the image right here is the website latest and you can see the name the id and it's mapping paul 8080 from the host to 80 inside of the container and the crucial thing here is that we are not mounting any volume so this image contains everything that our application needs in order to run now let's go ahead and test this in our web browser and then this was the previous one so now if i refresh you can see that this still works so if i open up safari and then localhost and then 8080 there we go you can see that our website is working beautifully and there you go you've successfully managed to create a docker file and then build an image from it and run a container if you have any questions go ahead and drop me a message otherwise let's go ahead and learn a bit more about docker files alright let's go ahead and switch context and build an api using node.js so we're going to pretty much just switch from this awesome website to building an api using node.js so go ahead and install node.js in your machine so for windows and mac users the installation process is the exact same thing and very straightforward so go ahead to nodejs.org and download either the recommended version or the one that contains the latest features so once you have node.js installed we're going to be using this awesome framework called express so express allows us to build apis and web applications so once you have node.js installed go ahead and navigate to expressjs.com go ahead and click on getting started and then installing so to install is very straightforward you need to create folder npm init and then entry point this will be the index.js and then you simply install the express framework so let's go ahead and do that now so let me go ahead and open up terminal and what i'm going to do is come out of this the website folder so cd and then dot dot and in my desktop i'm going to create a folder so make and then there and then api or actually let's name this as user and then service so this user service will contain every single piece of code that deals with users so let's go ahead and pretty much just make this lowercase u and then this also let's go ahead and say dash and then service and then enter or actually let's also say api so user service api and then enter let's go ahead and navigate to user service api now let me show you the actual version of node that i have so node dash dash and then version and for you it might be a bit different but this will also work for you regardless of whatever version you are using so now let's go ahead and say npm and then init and go ahead and pretty much just press enter a couple of times and then simply say yes it's okay now inside we have this package.json now let's go ahead and install the express framework so npm install save and then express just give it a second and there you go you can see that was very fast now go back to the website and right here so on the actual header click on getting started and then hello world so right here you can see that they have an example of how to run a very simple server with one route that simply returns hello world so go ahead and copy all of that and what i'm going to do is open up vs code so let me go ahead and simply open and then in my desktop user service api and then open there we go now inside let's go ahead and create an index dot js and then paste that code so just simply paste everything and save it now the way that you start this is if i go back to the terminal and you can see that we have this index.js now go ahead and simply type node and then index dot js and you can see that we have a message saying example app listening on port 3000 now let's go ahead and open up port 3000 on our web browser so localhost port 3000 enter and you can see that we have hello world now let me go ahead and simply change this a bit so right here instead of returning hello world let's go ahead and simply say res dot and then json and let's return a user so name bob and then email bob at gmail.com so this will be enough save this go back open up terminal again so we need to stop this ctrl c and then let me clear the screen and then say node index.js and there we go app is listening on port 3000 let's go ahead and open up chrome again refresh and you can see that now we have a json object back and in fact this should be so so let's go ahead and actually um return an array so an array so anyway here and then close that one there as well so this is a single object but we want an array so let me go ahead and cancel again there we go if i open up chrome refresh and now you can see that we have an array of users and there we go so you've successfully managed to create a very simple api with express next let's go ahead and dockerize this api using a docker file all right let's go ahead and decorate our node application written with express.js so currently we have an express app that simply has one endpoint and it simply returns a list of users so let's go ahead and actually take all of this and create a docker file that will allow us to produce a darker image so let's go ahead and create a docker file so docker and then file so now we have to choose the base image so let's go ahead and simply say from and if you have guessed it so if i open up docker and then hub and i can go ahead and search for node and you can see that we have one verified content and this is the docker official image so this means good news as we can use node for our base image so let's go ahead and simply say from and then node and then let's go ahead and pick the latest tag so i'm going to discuss tags later on but for now let's go ahead and use the latest tag next let's go ahead and use work and then there so work directory so what i want to do is actually set the working directory inside of the container so what i'm going to do is create a folder called app so basically this means that if you have a folder inside of the container called app use it otherwise create a brand new one and then any commands that follow this line right here will be executed inside of this app folder inside of the container next let's go ahead and pretty much just say add and we want to add everything so we want to add everything inside of this directory to the app directory next let's go ahead and use the run command so run and right here the run command allows us to pass few arguments so the arguments that i wanted so the argument that i want to pass is npm and then install so basically we want to install all the dependencies from our package.json so this allows us to do that and finally once we have all the dependencies installed we can simply go ahead and pretty much just type the same command that we did here so right here if i cancel this ctrl c node and then index.js so let's go ahead and simply say cmd for command and the command is node and then index.js and there you go this is pretty much everything we need for this docker file now go ahead and open up terminal or command line and let me go ahead and pretty much just press ctrl c clear the screen let's go ahead and simply say docker and then build and make sure that you are inside of the user service api folder and let's go ahead and simply name this as user dash service dash api column and then latest and i forgot to add dash dash tag or dash t so dash t for tag and then where the docker file is is inside of this directory so dot and then press enter and you can see that there are five steps so the first one is from node you can see that it's pulling node so these are layers which i want to discuss later on but for now it's just downloading everything that it needs for step one out of five so just give it a second and you can see that this is the one that taking the longest so this has um quite a big size right here so 215 megabytes so i think this was me actually um dragging this so just give it a second and you can see that this id right here is the same as that one so just bear with me now it's extracting there we go so you can see that now it's doing the oh actually this is very fast but basically you can see that it's finished but let me show you exactly what it's doing so the step two was creating the app directory and then step three out of five was adding everything from our local machine to the container and then step four was running npm install to download and install all the dependencies and then step five is the command so when this container starts what command shall be executed note and then index.js and you can see that this is the image id and this was the actual tag so user service api and then latest and this was actually me copying and pasting so ignore this and there we go now we have an image for the user service api written with node and express.js let's go ahead and run a container from the image that we've just built and what i'm going to do is make sure that the api is not up and running so let me go to localhost 43000 you can see that it's not up and running now let me go ahead and check the list of images that i have docker image and then ls and you can see that we have two extra images so this one node and the one that we've just built so user service api so you can see the tag as well so the tag is latest and the image id created at and also the size so now let's go ahead and pretty much run a container from this image right here so to do that let's go ahead and simply say docker and then run dash dash name let's name it as user and then dash api and the actual um and then dash d for detached dash and then p for mapping the host port to the container port so let's map the port 3000 and remember correctly so if i open up chrome it was running on port 3000 so this is the port that express.js listens on by default so let's go ahead and pretty much just map to that so the host 3000 will map to container port 3000 and then let's go ahead and pass the actual image so user dash service dash api and then column and then the tag is latest and i can see that i've got a mistake so this should be docker and then run not run and then press enter and there we go now go ahead and simply say docker ps with format or without it doesn't matter so i'm going to format the ps output enter and see that we have two containers so we have the website so this is running on port 8080 and this is the api which is running on port 3000 so let's go ahead and test it out so let me open up chrome and then right here you can see that this was running from our machine before and now it's been containerized with docker so if i refresh you can see that now it's working and also our website is listening on por 8080 and should work so you can see that it's working and there you go you've managed to containerize an express application with docker if you have any questions on what we did here drop me a message otherwise let's move on in this section let's go ahead and learn some of the best practices when it comes to writing docker files so in this video i want to cover the dot docker ignore file so so far you've seen that we wrote this docker file right here that says from node latest and then we set the working directory right here and then any command that follows will be executed inside of this folder called forward slash app so you can see that right here we simply add all the contents within the host so all of these files to this folder right here called app inside of the container and then we simply run npm install so usually when you write applications there are certain files that you should ignore for example if i was to commit this api to a github repository i wouldn't necessarily commit this folder right here called node underscore modules because this folder right here is created when we run npm install so in fact let me go ahead and delete it so let me go ahead and simply delete and then you can see that if i try to run this application so let me go ahead and simply say node and then index.js you can see that cannot find module express so what we do is simply say npm and then install or npm i there we go you can see that the packages were added and about 50 of them now if i go ahead and say node and then index.js you can see that this time this works so what we need to do is right here so because we don't need to include this folder to our build step inside of this docker file right because this command right here so run npm install does it for us we simply have to exclude this file right here and so that you understand by the time you run this command right here it will include everything in this folder including node modules then you will also run npm install and that will create the node modules again so we don't need that so what we need to do is create a new file and this file will be called dot and then all lowercase docker and then ignore and then press enter now what we need to ignore is node underscore modules and in this file you should ignore folders or files that your docker image does not need so we also don't need the docker and then file so we don't need this docker file so this one right here to be added to our image right so it adds no value because we don't need this docker file in order for our application to run finally because i'm going to create a github repository from this example right here let me go ahead and simply add a dot and then get so this is the git folder and i really don't need to include that inside of my image and for example if you want to exclude files ending in certain extensions you simply say for example a file or actually it's a star so any file ending in for example dot and then gulp for example.js something like that uh if you want folders you'd say folder and then forward slash and then any folder under that right and this is pretty much it so i'm going to ignore node modules docker file and dot get so now if i go ahead and save this and let's go ahead and pretty much cancel out of this let's go ahead and build the image so docker build and in fact let me check the image name so docker image ls so the image was user service api so docker build dash t paste that let's also go ahead and simply say lay test and then dot enter and you can see that it's running it added 50 packages so this was the npm install and there we go and this is how you use the docker ignore file if you have any questions go ahead and drop me a message otherwise let's move on in this video let's go ahead and learn about layers and caching when building images from our docker file so pretty much every one of these steps so step one to five they do create layers and a layer is used in caching so how is this important to us so what i'm going to do is pretty much open up terminal and right here let's go ahead and install few dependencies npm install dash capital s let's go ahead and install react web pack and then let's also go ahead and install gulp and grant so basically i'm just installing random packages that you don't necessarily need so this is only for demonstration purposes so go ahead and press enter and you can see that this will take a while so it will download react webpack gulp and grunt so just bear with me and there we go you can see that it added few packages and this took a while so now let's go ahead and open up our code and what i want to do here is open up index.js and if i make this smaller so you can see everything so right here let's simply go ahead and add another user so let's call this alice and then alice at and then hotmail.com now let's go ahead and build an image from this so go ahead and pretty much just press up couple of times and what i'm going to do is uh this one so i need this command docker build dash t user service api and then latest and then dot so you've learned about this so now go ahead and press enter and you can see that these are the steps and each step so you can see that right here so this step is using cash so you can see that it's using the cash right so just give it a second and you can see that now this will take a lot longer because we are installing a bunch of dependencies and you can see that it's finished right so the point really here is that you can see that step one is pulling the node image so latest and then work directory is using the cache but really there is not much going on inside of this work directory so this is simply saying create this folder if doesn't exist otherwise use it and then we add the source code right here and then we run npm install so if i run the application so let's go ahead and run so run just like that press enter and there is a container already so let me go ahead and say docker rm and then dash f user dash api there we go that's gone so if i run this again and then open up my web browser and if i refresh you can see that we have two users right here so we have bob and alice now let's go ahead and add a third user so right here let's go ahead and add jake jake and then add and then yahoo.com save this now let's go ahead and build an image again with our changes so go ahead and pretty much just say docker build basically the same command press enter and you can see that it's running the same thing so basically from node right here using the cache adding our source code right here and then running npm install and you can see that took a while so the thing here is that we can do way better than this so we can take advantage of caching because the only thing that we have changed was the source code so because the source code has changed right so let me go back to the docker file that we built so because this step has changed docker has to recompute every single step that comes after this so the way to improve this and to make sure that we do not run npm install and download and install dependencies all over again we can simply take advantage of caching so let's go ahead and think how we might improve this docker file so we know that what we need from this docker file is two things we need the package.json and package.log.json so what i'm going to do is i'm going to set the working directory and now here i'm going to say add and then i'm going to say package and then star dot json so basically uh i actually missed the dot right here so we want to add package.json to the working directory which is app so basically now we are adding the package.json right and what we're going to do is pretty much uh run npm install and then after that's complete we're going to add the source code so we're going to add everything from the current directory right here to our working directory inside of the container which is app and then we're going to run node and then index.js so this will improve things dramatically because we don't often change what's inside of the package.json surely at the beginning of development but once the software is mature enough we don't necessarily add too many dependencies so we can simply use caching right and then docker will know whether the contents of package.json or package dash lock.json changed and then recompute everything all over again if not it will just skip this step use whatever it's been cached and then pretty much just add the source code and then run node and then index.js and this will be way much faster so let's go ahead and give that a go so let's go ahead and build so let's go ahead and build this for the first time so docker build minus t user api and then call them latest and it says when using add with more than one source file the destination must be a directory so what i need to do is simply say forward slash and then dot and this should work and i think i got mistakes so this should be dot and then forward slash like that and let's go ahead and give that one more try so docker build and there we go so it's working now so you can see that right here so he's pulling the node image he's using the cache for the working directory and it's added the package and package.oh actually package.json and then at package.log.json and then right here it run an npm install right and this is done so right here so you can see that step five was simply adding the source code and then step six and then step six is the actual command so node index.js so now let's go ahead and pretty much just add a fourth user so right here so let's go ahead and add maria and maria at yahoo dot and then com dot uk something like that and then let's go ahead and go back and now let's watch this closely so now if i build an image from this docker file guess what so you can see that this was so so much faster and why it was simply because of this step right here so right here you can see that it's using cache which it wasn't before and the same for the package and then start.json so nothing has changed there and in fact you can see so let me start from the top so right here using cache so this is for the working directory the same for adding package.json the same for npm install right here so this is awesome and then the only thing that changed was the source code which was inside of this step and this is much better because now we are using caching and you can see that building images this way was much much faster so bear in mind when you create your docker files to think exactly what will change and what will not and try and make use of caching whenever is possible now let's go ahead and test this by bringing up a container from this new image so let me go ahead and check the images that i have so docker ps let me clear that and we have this user api so let's go ahead and stop it so docker rm-f so we're going so we want to stop and remove and let's go ahead and say user api now let's go ahead and simply start user dash api like that and this will be using the new image so press enter there we go now if i open up my web browser and then right here let's go ahead and refresh you can see that it's working we have maria right here so maria was the last user that we added and there we go now we have an understanding of docker caching and layers go ahead and drop me a message if you have any questions otherwise join me on the next one all right in this video let's go ahead and learn how we're going to improve our image sizes with docker so let's go ahead and simply uh check the images that we have so docker and then image ls and right here you can see that we have a couple of images so we have our custom image that we've been working with so user service api latest and we also have the website image node and then ngx so if you look carefully so we have this size column right here and you can see that the size is to be honest quite large so this is almost one gigabyte right but then if you look into this website the nginx one right this is base of engine x the size is 135 megabytes now when building images and pulling images you will see that the time that it takes to download these images is quite large so one way to reduce the image size is to use the linux alpine distribution so what i want to do is actually show you exactly what it is so go ahead to alpinelinux.org and right here you can read about it but basically this is a is an independent non-commercial general purpose linux distribution designed for power users who appreciate security simplicity and efficiency and right here you can see that the key points are it's small and you can see that a container requires no more than eight megabytes and a minimal installation to this requires 130. so you can see that you know the sizes here are really tiny really minimal it's simple and it's secure so go ahead and read more about the alpine linux distribution but what i want to show you exactly is how we can reduce the file size of our images because this is very important when you start building a bunch of darker images so let's say that you have 100 docker images right so one you will fill up your docker registry very quickly so you run out of space and we're going to touch about docker registries later and the other one is actually you know speed and also in the actual images that we have sometimes we don't need everything in it so that's why we use the alpine image so let's go ahead and learn exactly how we are going to reduce the file size of our docker images alright so pretty much every single docker image out there has an alpine version or actually an alpine tag so right here you can see that we have a node so this isn't ours and we also have nginx and they are using the latest tag so let me go ahead and show you the actual um image so this one is for node and right here you can see that they have supported tags so by default when we don't use a tag we pretty much just get the latest tag or as we've been using tags throughout this video we've we have simply been using the latest tag so right here you can see that they have a bunch of tags and the one that we've been using is node but you can see that for example you have 8.16 0 and then jesse you've got buster but more importantly the ones that we care right because we want to reduce the file size is the alpine version so you can see that h16 zero and then alpine and then you have eight dash alpine so let's go ahead and pretty much just pull an alpine image and then investigate the actual size so let's go ahead and simply say darker and then pull and what we're going to do is we're going to pull node and then say column and then lts for latest and then dash and then alpine now let's go ahead and press enter and you can see that this is pulling the image from library dash node and you can see that this is 21 megabytes and pretty much it's done so you can see that it was very very quick so let me actually go ahead and pretty much just clear the screen darker image ls and now take a look at this you can see that now our node image so latest alpine it's only 75 megs so we went down from almost a gig to 75 megabytes so this is insane and you saw that to pull this image was like very very fast and remember previously when we pulled this image right here right so when we pull this image this took ages so you know i had to wait because my internet connection was slow but right here you saw that pulling this image was very very fast let's go ahead and do the same for nginx so go ahead and simply say docker pull and let's go ahead and search for the latest nginx tag so let me go ahead and pretty much just navigate and search for nginx and let's look at the tags that they have so you can see that they have also alpine right and they have latest so let's go ahead and pretty much just say that we want the latest actually nginx here first so this is the um name so repository name so n g and then x column latest dash alpine press enter and you can see that it's actually not called nginx dash or nginx column latest alpine so so i think that okay i got mixed up here so basically uh if we want alpine we simply say alpine and then it will get the version right so basically these are the versions and if you don't include the version right so if we simply say alpine you will get the latest one so let's go ahead and pretty much just run the same command again and instead of latest we simply say alpine enter and there we go so now you can see that it's pulling the image and this was like very fast so let's go ahead and clear the screen and then docker image ls enter and now let's look at this so basically we now have two nginx images so this one was the latest right and this one is the alpine version and you can see that the size this one is pretty much tiny in comparison with this one this one is 126 megabytes and this one is only 21 megabytes and this is awesome there we go you now know how to reduce the image file size by using the alpine linux distributions when pulling docker images next let's go ahead and change our own images so this one uses service api to use an alpine version and the same for our website let's go ahead and change our custom images to use the alpine version and you will see that the size will become much smaller so let's go ahead and change for the user service api and the same for our website so let's go ahead and open up vs code or your favorite ide and i'm inside of our api and what i'm going to do here is pretty much change this to alpine and i think that right here we use the lts alpine so let's actually double check what's the difference between alpine and lts alpine so let me actually go ahead and go to docker or actually node so node and right here so we have the alpine version and lts and then dash alpine so basically i think i've used this one previously but we also have the alpine right here so let's actually use the alpine so what i'm going to do is pretty much just say node and then alpine here save that and let's also go ahead and say docker rm or actually image rm and then node and then get the actual id so let's remove this image there we go that's gone and let's do a docker pull and then node column all and then fine so i think this is much better there we go and you can see that this will be super fast there we go that's done so if i do a docker ls image or actually image ls you can see that we have node alpine right here and it's only 79 megabytes so that's fine now let's go ahead and change the actual uh website so let's go ahead and open up website so file and then open and desktop and then website and right here this will be nginx and then alpine save this now let's go ahead and build these two images so docker build and we are going to build the user service api right so make sure that you are inside of the folder and then name this as latest and then simply say dot press enter and i always forget the tag so let's go ahead and simply add a tag build and then dash t for tag there we go so you can see that now it's pulling from node alpine and this is taking a while because of caching so remember that this layer right here so this layer right here has changed right therefore we need to recalculate everything that comes after it even the work directory remember before it was getting from the cache the same for package.json and npm install so we've changed the image so now it's recalculating everything so if i actually go ahead and i'm going to show you this so if i build the same image again so this was like super fast because it's using the cache right here you can see that it's using the cash using cash cash cash cash and cash because nothing has changed now let's go ahead and cd back and then go to website and let's go ahead and pretty much just build website so docker build dash t and then web site colon late test and then dot enter and there we go you can see that this took like you know probably half a second or so and this is because there is there isn't much that we have to do in this build because we simply are pulling alpine and then adding the source code and that's it so now let's go ahead and say docker and then image and then ls so now you can see that we have the website right here right so the website now is only 30 megabytes and before was 134 so i'm going i'm going to explain this later on but you can see that now we have none and none so the repository went from none and the tag also went from none and that's because we are overriding the tag so it's pretty much reusing the same tag and because you cannot have images with the same repository and tag with the same repository name and tag it simply removes and then uses for the new build so that's what we did that's what it did here so website latest is only 30 megabytes so you can see that it went from 135 to 30. so this is a big improvement now let's look at our user service api so remember this was based off node so this big one right here almost a gig so now it's actually 117 megabytes and before you can see that right here so this one it was 100 it was 946 megabyte which is almost a gig so there you go you can see that we've managed to improve the file size of our custom images if you have any questions on reducing the file size go ahead and drop a message otherwise let's move on in this section let's go ahead and learn the importance of tags versioning and tagging our own images so basically tags versioning allows you to control image version i.e you have full control of what image you pull and what image your application depends on and the benefit of that is that you now avoid breaking changes so let's say that you code against node 8 today and then tomorrow node let's say 12 comes out if you are using the latest then you pretty much you know switch to node 12 without testing whether your application works on node 12. i'm going to give you example in a second about this and also it's safe right so when you build images you have to make sure that they are safe you have to make sure that you fix any security patches and with tags and versionings you can achieve that so let me give you an example of tags and version so let's say that today you run docker pool node alpine and the current version of node is eight just imagine right the current version of node today is eight and then tomorrow you run the exact same docker pull command so docker pull node alpine and then the node version is 12. now how do you make sure that your application that you have bundled against node 8 works against node 12. you don't know right so this could have an impact on your application and you could have lots of breaking changes so the same if you are using node latest right so the alpine version it's pretty much the smallest linux distribution but it would be the same thing so here you are pulling the node latest and is the exact same example now the better way of doing this is that you have full control so what you do is pretty much say i want to pull node and then you say 8 dash alpine so right here you are literally specifying the version that you want and then tomorrow if note 12 comes out you can decide whether to switch to note 12 or not right but right here you have full control of the version and tags that you are using let's go ahead and change our current images both nginx and node to point to a specific version and tag all right go ahead and open up the docker file for our website and let's go ahead and change this very first line so from nginx column alpine to use a version right so right here we are simply depending on the latest version of engine x right so the smallest distribution right here but we want to stick to a version and have full control now where you actually find the versions is if you go ahead and open up docker hub so let's go ahead and search for nginx and and then genex so this is a verified one and right here you can see that supported tags and respective dockerfile links so right here you can see all the tags with versions so right here you can see that so we are using the alpine version right here alpine but what we want to do really is just is just stick to a version right so you can see that we have 117.2 or actually 1.17.2 dash alpine so you could go ahead and also try all of the other versions but as we've discussed in this course the alpine is the preferred choice when building darker images so let's go ahead and pretty much just stick to this version right here 1.17.2 dash alpine so let me go ahead and simply grab that and then simply say 1.17.2 dash alpine so this is my tag now i have full control let's go ahead and also do the same for our api so go ahead and open the user service api and there you go so right here you also see that we have from node and then alpine so let's change this to use a specific version and tag so go back to docker hub and then let me go back and right here you can see that you have a bunch of tags right so let me just quickly show you that if you go to nodejs.org right here you can see that they have two versions right here so they have the 10.16.1 so this is the latest recommended for most users and then you have the latest features so this is 12.7.0 so go ahead and pick the one that you feel most comfortable with so i'm going to go with 10 so no 10 the recommended for most users so let me go back to docker hub and we should have a version 10 and by the way that version might be different for you depending when you watch this video so let me actually go ahead and search for the alpine version and i want 10 so you can see that right here we have 10.16.1 right so this is pretty much the same one so let's go ahead and um take this so 10.16.1 so let me go back to vs code and this will be 10.16.1 dash alpine and to be honest this is all so you can see that now we have full control of these versions the next thing that we have to do is simply build these images and see the next thing that we have to do is to build these images and make sure that everything is working fine so next let's go ahead and build and run the containers using these tags with a specific version all right let's go ahead and build images for these new tags and then run the containers so i'm inside of the website folder so let's go ahead and simply say docker and then build dash t web site and then column latest and we also will learn how to tag our custom images but for now simply say latest and then dot press enter and now you can see that it's pulling from and you can see the tag and ver or actually the version and tag that we have specified so engine x one point point let's go ahead and do the same for the api so cd and then back a folder and then user service api let's go ahead and tag the same thing so i think this was user dash service dash api and then press enter there we go now you can see that this changes right and because i've changed the version it's not using the cache it has to recompute everything again so just give it a second it's running npm install and there you go now if i go ahead and clear the screen and say docker and then image ls you should see that we have user service api and website now don't worry about seeing lots of none here and i'm going to explain why this is happening later now let's go ahead and run both the website and the user service api so docker and then run and let's go ahead and run that um expose import 3000 and it seems that we already have a container with that name so docker and then rm dash f and then grab the name and i think it should be just that so that's incorrect so docker and then ps or docker ps a and you can see that we have to remove user api so let's actually run the same command so it should be that so user and then dash api there we go and let's do the same for the website so website now let's go ahead and create a container or run a container for our api first and then let's run our website container so a website and if i search we should have a website like that and then enter there we go now let me go ahead and open up chrome and if i go to localhost 8080 so this is the website you can see that this is now working with a specific version and tag and let's also do the same for our api so if i refresh you can see that this is working so now we have full control of tags and version for our docker images if you have any questions on this go ahead and drop me a message otherwise let's go ahead and learn how to properly tag our own images so before we learn how to tag our own images go ahead and type docker image and then ls you can see that we have four images right here that have no repository nor tag so this is because every time we made a change and we use the same tag so latest so this tag right here so website dash latest we have to override the existing image so what i'm going to do is actually build this and i want you to see that this will remain with four of these because it will use the cache so if i do a darker ps or actually image ls you can see that we still have four but now let's go ahead to docker hub and let me go ahead and search for nginx and let's go ahead and pretty much just use one alpine so this version right here so go back to vs code and then open website and then right here simply say one alpine save this and then let's go back to terminal and then run it so let's actually tag this again so let's now build an image for our website and use the same tag so website column latest and you can see that now it's pulling the one version one dash alpine and successfully built a tag so now remember right here so this is the one that was using this version so let me actually go back and then uncomment this and save because i want this version so this version right here right is for this one but we have named it as latest now if i go ahead and clear the screen and let me actually delete that and simply click this card again and say docker image and then ls now we should see five images without a repository and tag so this will override so there we go you can see that now we have four and five right so now that you know that whenever you make a change to your image and then use the same tag you will override the existing one remove the repository and tag next let's go ahead and learn how to properly tag our images all right so currently we have this website right here right so if i show you so we have this website greater scale and pretty much we haven't done anything with this website we haven't modified it we haven't done any anything so usually you add features incrementally and then you have an image for a complete feature so let's say that we want to update this website right here instead of grayscale we want to say amigos code or your own company so the way tagging works is what i'm going to do first is collapse that and i'm going to build so i'm going to build a new tag so this time i'm going to call it website or actually amigos code and feel free to use your own name if you want so i mean it was called website and this is the latest so this is the latest one so i'm gonna build this and you can see that now if i do a darker image ls you can see that i have now amigos code website and this is the latest now the way i'm going to tag this is based off latest and then use a specific version so let's go ahead and simply use this docker and then tag and we want to tag from amigos code dash web site column latest and from that we want to build a new tag so let's go ahead and simply say amigos code dash web site and then column and then one so if i press enter you can see that this works and now if i do a darker and then image ls you can see that i have latest right so this is the latest version but we also have the versioned number so amigos code website and then this is version one now both of these images they do have the same contents as our running website so this one so now what i'm going to do is open up vs code and open up the website folder let me make this smaller so you can see exactly everything open up now index.h scroll to the bottom and you should see the h1 right here grayscale and change this to amigos code or your own name and you can also go ahead and change this description the same with that one but for now i'm going to simply save this as is so now i'm going to save this and then open up terminal and now i have a new change and what i'm going to do is tag again so i'm going to tag this as latest so this now is the latest image that contains our changes so i'm going to press enter there we go and now watch this i'm going to tag from latest and then i'm going to create a new tag right here this is a tag name so from so tag this is the from and then this is destination now here i'm going to say this now is version two press enter and if i clear the screen docker image ls and there we go so now you can see that we have amigos code website one amigos code website 2 and we also have latest so this will always point to the latest tag number so now let's go ahead and spin up two containers one using the first version of the website and the other one using the second version of the website and also why not let's spin up the one using latest so let's go ahead and do that in the next video all right let's go ahead and run a container for amigos code website tag and then one amigos code website tag and then two right and let's also run one for amigos code website and then latest so i want you to see exactly how this works now let me go ahead and clear the screen docker ps so let's go ahead and kill the website so this website right here because we're going to reuse this port right here 8080 so say docker and then ram dash f and then web site there we go and let's also delete the user api so why not there we go so now if i do a docker ps you can see that no container is running now let's go ahead and run the website and then version one so let me actually copy from here so right here let's go ahead and say amigos code website and then latest and then this will be amigos code website and then the tag is latest so this will be 80 80. now press enter and there we go let's now change this to 2 so this will be the version 2 and let's go ahead and change the name because they can't be the same and the same with ports so this will be 8081 enter and now let's go ahead and run the version 1 and this will be on 8082 and then this will be one so amigos code and then one well actually it could have said amigos code website one for the name but it's fine you get the point now if i press enter you can see that they are both running so now let's actually do some testing so remember right so remember the latest one the latest one was based off the version two right so if i refresh this page you can see that now i do get a miko's code now let's go ahead and change this to 80 81 and we should also get amigos code because this is the version 2 and version 2 contains the latest changes and this one running on port 80 is the tag amigos code website and then latest and it's based off version two so that's why they are the same now let's go ahead and run localhost and then 8082 so 8082 is running the first version of our website now the contents should be different because we are running a older version if i press enter you can see that now this says gray gray scale and this is the power of you having control of whatever version that you are running when you deploy your website because let's say that you have deployed version two now let's say that you had a spelling mistake and your css had a bug right so or even like a button right so this button wasn't working for some reason now instead of you taking time and fixing you know the you know why the button was it wasn't working and all the spelling mistakes what you can simply do is go back to a previous version and then while you fix it you are guaranteed that your website was working as it was before right so you could go back to this version right here without no problems and then fix your bugs and then create a brand new version so then you create version three and then deploy that so this is how you tag your own images using docker so if you have any questions on tags go ahead and drop me a message otherwise let's move on and learn how we're going to push our images to a container registry in this section let's go ahead and talk about docker registries docker registry is simply a server side application that lets you store and distribute darker images so far we've been building images in our host machine but eventually we want to take our images and store it in a server-side application so that's what docker register is we also can use docker registries for our cdci pipelines i.e continuous delivery continuous integration pipelines so usually this is when you pretty much just spin up a bunch of images to achieve a certain task according to your pipeline and also it's used for running our applications so you can take your container from your host upload it to a docker registry and then use it to run instances of your application right so as we've been doing running containers and you could use for example google cloud with kubernetes or some of the services provided by aws such as elastic bean stock so the idea is that you have images in your host so this is our current scenario as we've been doing throughout this course and you also have a docker registry so a docker registry as i mentioned is simply a computer server that holds all of our images and to ship images to any docker registry is very simple all you have to do is use a command called push and that takes the images and puts it inside of the docker registry and we're going to learn about this in a second so when it comes to docker registry there are two types you have private and public registries so it really comes down to your needs so you might have images that you don't mind other people see it and use it or you might have personal projects or you are working on a an application that you don't necessarily want people to have access to your image so that's when you use a private registry in terms of docker registry providers there are quite a lot of providers but let me just mention the most popular ones so you have docker hub so this is where we've been pulling public images such as nginx and node you also have key.io and also amazon ec2 container registry let's go ahead and push our images to docker hub all right let's go ahead and take our images that are running the website as well as the api and store them in a container registry so for this course we're going to be using docker hub so navigate to hub.docker and make sure that you are signed in so docker hub gives us the ability to store both private and public images so in fact when you go to docker hub so let me go into docker hub and right here let's go ahead and simply search for an image so right here you can see that they have a bunch of images but all of these images they are public so if i pretty much click on you can see that i can pretty much just say docker pull so let's go ahead and also store our own images so go ahead and pretty much as i said navigate to hub.docker and make sure you sign in and then right here you can see that they have this section here this menu item repositories so go ahead and click on it and there you go so you can see that i have no repositories found so let's go ahead and create one and also so just to bear in mind that you can see that they give you one private repo so that's really really awesome so if you have for example a website or a full stack web application you can take advantage of this private repo and then have an image that you are the only one that has full access and control to that image so let's go ahead and create a repository and you can give a description right here you can give a description but let's go ahead and create one first for the website so website and then give a description so let's say main web site and you can elaborate on this so what i'm going to do is actually select public so i don't need this to be private because i want to share with you and then go ahead and simply say create and there we go so now we have a repository so you can see that right here the way that you push images it's very simple so you simply say docker push and then this is your account this is the actual repository so website and then the actual tag name next let's go ahead and learn how we're going to take an image from our host and push to our repository hosted by docker hub now that we have a repository with docker help let's go ahead and take an image from our host and push it to our repo so you can see that right here they have this command right here so you can see to push a new tag to this repo simply say docker push and then this is the username and then this is the actual tagging so what we need to do is first let's go ahead and pretty much close this so what we need to do is simply say docker image and then ls so you can see that we have few images right here you can see that the repositories are a microscope website you can see that you have node nginx a user service api you might even have more or less than me so what we're going to do here is simply take migos code website latest amigos code website 1 and also 2 and let's push all those three images so what we need to do here is to tag a new images according to the following so so the first part is username website and then tag name so let's go ahead and do that so let's go ahead and simply say docker and then tag and then amigos code dash web site and then column one and then we want to tag this to amigos code forward slash website column one so this will be our new image right here so let's go ahead and press enter let's do the same so right here will be two and then this is two so remember tagging so this is the source so the source is this one so amigos code dash website two which is this one and then this is the actual new name so amigos code for slash website column two which is pretty much uh the same as this one right here right so i'm following this standard so let me go back and then press enter and let's also take latest and latest here right so we have a latest right here so this one now press enter if i do a darker image ls you can see that now we have amigos code for slash website and then this is one amigos code for slash website 2 and amigos code forward slash website and then latest now the way that we push these images is first you have to log in so you can see right here in this docker logo so you can see that i'm already signed in so let me go ahead and actually log out and you can log in in two ways so one you can pretty much click on the logo on the docker logo again and then sign in and right here you simply add your credentials or using the terminal simply type docker and then login go ahead and type your username so my one is amigos code and then type your password there we go so now that i'm logged in i can run this command right here so docker push and then the actual tag so let's go ahead and do that so um if i pretty much say docker push and then remember amigos code forward slash website column one press enter you can see that now it's preparing and it's pushing there we go let's do the same for the version two and the images are not that big to be honest right so remember we are using alpine and this is the benefit of alpine there we go and now let's also push latest and finished now if i go ahead and go back to docker hub now if i refresh you can see that i do have the three images right here so i've got version one of my website version two and the latest so this is awesome so you can see that now we have the images right inside of docker help and you know it's secure you can share it with other people and you can use it to run containers so on and so forth if you have issues getting this far go ahead and drop a message next let me go ahead and show you how to search and pull your own images alright so we've pushed these three images right here for our awesome website and inside of docker hub what i'm going to do is to click on docker hub so basically click right here and what i'm going to do is simply search for your own username so go ahead and actually search for mine for now so simply say amigos code and then you should see this repository right so this is the website that we've just pushed in the previous video so go ahead and click on it and you can see that no overview is available but if you are doing this for yourself go ahead and add more information because it's always useful for someone that wants to use your images so you can see that we have tags right here so these are the three tags that we've pushed and if i go back to overview you can see that the command right here to pull the image is simply docker pull amigos code and then forward slash website so let's go ahead and try that out so let me go ahead and open up terminal and what i'm going to do is simply say docker image unless you can see that we have amigos code website one here so let me go ahead and simply say docker i for image and then let's go ahead and simply delete the amigos code website column one as well as two and then latest there we go now if i do a darker image ls you can see that it's gone right so we have this amigos dash website and this is from previous videos that we've done now what i'm going to do is simply say docker pull and go ahead and also try this so simply say docker pull and then amigos code forward slash website and then press enter and actually before you press enter so because we're not specifying the actual version whether it's one or two we'll simply get the latest one so press enter and you can see that it's using the default tag and done now if i do a darker image ls you can see that we have amigos code for slash website and then latest right at the top now let's go ahead and run a container from it so run and what we want to run is the actual website so right here let me simply add a forward slash website and i think that port has been used already so let me go ahead and simply expose 9000 and then right here this is forward slash and then amigos code and then press enter and we can't use forward slash forward name so let me actually remove that and simply say website enter there we go now if i open up my web browser and then localhost and then 9000 and you can see that this is working and it should also work for you so there you go this is how you push images to a container registry we've used docker hub but the process for pushing to amazon ec2 container registry is the same and also if you are using key.io is the exact same process and one last thing remember that we had this api right here so what i want you to do is to experiment this process on your own so go ahead and push this that you have locally for this api to your own docker registry if you have any questions go ahead and drop a message and i'll be more than happy to assist in the meantime let's move on all right in this video let me go ahead and show you an important command that you might need to know in case you want to debug your docker containers so so far if i do a docker ps and then format you can see that i've got two containers running and this is the actual api and then this is the website version two now this docker ps command simply gives us some information about this container or actually these two running containers but sometimes you want to investigate fully the configuration for a container so the way you do it is simply by typing docker and then inspect so you want to inspect if i get this right so you want to inspect and then you can either pass the id or the actual name so id or name so let me go ahead and grab the id for our api paste that in if i press enter you can see that now this gives us a json format information and right here we have a bunch of information about this running container so if i scroll up so right here you can see that you have the id this was the time that it was created these are the arguments that we've passed remember so node and then index.js you can see the state is running paused so basically you can see the full state for this running container you can see the image you can see some information about the log path the name the driver platform its linux you can also see the actual host config so right here this is more about the networking part so you can see that right here you have a port binding right so right now you have 3000 being mapped to 3 000 on the host right so we've learned all about this and then you have stuff such as restart policies volume drivers so if i scroll up i just want to show you you can see that we have the cpu period uh devices memory swaps and right here you can see that we have some read-only paths and then if i scroll down you can see some information about the graph driver uh the mounts the configuration right here so we haven't got any some environment so this is uh this is the list of environment variables so right here so we have the path this is the node version right here so this is exposed by default and also the yarn version right here so you can see that and some networking settings again and there we go so basically sometimes when you want to fully inspect your container you pretty much run docker and then inspect and then the container id or name if you have any questions go ahead and drop me a message otherwise let's learn how to view logs for a container alright sometimes you want to view exactly what is going on with your container so logs so logs is a very important concept that you need to know because sometimes you might want to monitor the traffic that goes to your container or any other logs that you have configured so the way that logs work with docker is very straightforward so if i type docker uh actually let me just press up a couple of times so docker ps you can see that we have this user service api now the way that you can see logs about this container is if i grab that name and then type docker and let me clear the screen for now simply type docker and then logs and then paste the actual container id if i press enter you can see that this is the actual log that we saw way back when we configured expressjs so you can see that this says exampleapp listening on port 3000 so if i open up vs code quickly there we go if i go to index.js you can see that if i scroll down right here so this is the actual log so whenever you say console.log you can see that we can capture that with docker so if i now go back to my terminal and what i'm going to do is actually do a docker ps again and let's actually grab the logs for our nginx website so if i grab that and then say docker logs paste that in you can see that now right here we have a bunch of other logs so this is actually if you look carefully these are all the requests you can see that there is a get request right here another one here another one here and um yeah basically those and if you scroll up you can see a lot more right but what i'm going to do now is simply go back to chrome and let me go to my website refresh and then go back to terminal so i want you to see this so now if i do a docker logs on the nginx website you can see that we are getting some requests so this is really cool because now you can see exactly all the logs and if you want to for example ship these logs to a service such as yumio or elasticsearch then you can do it right so what i'm going to do here is show you that you saw that i can type docker logs every time to inspect the logs but also there is this flag right here dash and then f and this means to follow so if i press enter you can see that now if i pretty much refresh this so actually let me put it on the side like that and this also now right here if you watch the right hand side if i pretty much just refresh you can see that this also refreshes and you can see that we get a get request right here so if i press and get started obviously nothing happens because this is a single page website but you get the idea right so if i refresh again you can see that it's following the logs so this is awesome and if you want to learn more about logs so let me just resize this and then put in the middle if i cancel out of this so control c type docker and then logs dash dash and then help and this will give you all the commands that you can use with logs so go ahead and experiment with logs but this is very important when you want to debug your containers or everything that you log in your apps if you have any questions go ahead and drop me a message otherwise i'll catch you in the next one all right so sometimes you want to get into a container and see exactly what is going on inside of the container right so you want to go inside the box and see exactly what is happening so remember when we did type docker and then ps and let's go ahead and grab the user service api so let's go ahead and grab that enter uh oh actually not ps but i want to inspect so inspect so right here so remember that we saw that the actual box was linux so the platform was linux right here so sometimes you want to get into the box and and pretty much just navigate your way around or you might have installed some software on the box and pretty much you just want to debug even further why certain things are working so the way that you jump into a container is simply by typing docker or actually first let me go ahead and describe all of these again so you can see so the way that you jump into a box is simply by saying docker and then exec and then dash i t so let me actually go ahead and simply say help so you can see the exact commands so right here you can see that i stands for interactive so keep the standard in open even if not attached and then dash t allocates a pseudo tti so let's go ahead and simply type the exact same command so docker exec dash i t and then paste the actual uh container id and in fact i forgot so let me format this again and then grab that container id and then let's say dash and nit past the container id and then right here simply go ahead and say forward slash and then bin forward slash bash and then press enter and this failed but it failed because we don't have bash here and what i want to show you first is actually if we grab this id again so let's grab this id docker inspect so this is how you use your debugging skills and then search for cmd and there you go so right here you can see that the command that it was used to execute node was forward slash been sh c and then node index.js so let's go ahead and clear this and now if i pretty much say docker exec it now you can see that i can simply say sh enter and now i'm inside of the container so if i type ls minus al this is pretty much the working directory that we have set within our docker file for this api so if i type pwd you can see that i'm inside of four slash app so if i do a cd and then dot dot go back same command again ls dash al enter and now you can see that this is the actual linux file structure assalamu alaikum i'm super excited that you've made this far so you saw the power of docker and what you can do with it so i'm a devops engineer and i use docker every single day and i can tell you that by knowing how to use docker you now can explore paths such as kubernetes so kubernetes takes the advantage of containers and then orchestrates those containers for you so go ahead and check my website i've got a full course waiting for you on kubernetes if you haven't joined the private facebook group go ahead and join and also discord we are waiting for you give me a thumbs up so i can keep on recording these videos subscribe to my channel and this is all for now i'll catch you in the next one [Music] you
Info
Channel: Amigoscode
Views: 99,451
Rating: undefined out of 5
Keywords: what is docker, docker tutorial, docker container tutorial, docker container, docker images, what is docker container, learn docker, docker container basics, docker hub, docker tutorial linux, docker compose tutorial docker tutorial for beginners, docker crash course, docker for beginners, dockerfile, getting started with docker
Id: p28piYY_wv8
Channel Id: undefined
Length: 180min 2sec (10802 seconds)
Published: Sat Oct 24 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.