 So, basically a little bit about the Docker workshop. So initially it's me, Michael and another colleague of ours. We wanted to also educate the colleagues in our company about Docker. So actually the materials came up together to help our colleagues thus to have the fundamentals of the Docker experience and also to teach about what is Docker entirely about. So after that we moved to... So we taught one round in SP, single poly. And that's why Michael was saying that if you guys have windows and it's a lot more difficult because a lot of students in SP will have windows issue. I think you will know about it and everybody here will know. So thank God that you guys are Mac. So before that I did a bit of slide. So make sure that you guys can see this. So your very first intro to Docker is the command called Docker Run. So basically when you do that you'll get to see a whole bunch of message. This also tells that you have successfully managed to run Docker on your computer with an image called hollow work. But we explain what is the image, what is the command all about. So in the next it's... So maybe does want to know what have you all heard about Docker. Thus to have the impression that you all have what is Docker. Like with environment. Correct? Anything else? It's a wheel with a lot of containers. That's another one. Anything else about Docker? Correct. So that's also another beauty or the thing about Docker that's why it's so popular. It's the ability to make sure that your local environment works exactly the same as the other environments also. Anything else? Or it's cool technology. Everybody is doing about it. I think it's nice to put on the resume. If you're able to skill up. So the idea of containers also come from when Google first started. That's how they deploy a lot of their services also. They deploy containers across all their thousands of servers. So that's also right. So actually Docker is a relatively new technology. It only started in 2013. And when we say Docker, actually Docker is a set of tools that is being composed together to have Docker. So if you want to know more about this set of tools you can look at the MOBI project. This is the project where these are the tools that Docker use to have what you have today. So if you are really hardcore you want to create your own version of Docker or if you want to do something your own you can go and check that out. So the reason why a lot of why Docker run better on Mac is because it runs on this thing called Linux Kit which naturally says that it runs on Linux. Hence, when you run on Windows there's a little bit more issue than needed. Okay? So like you say Docker works well with a lot of the other orchestrators what decoy the orchestrators where they take the containers and then deploy to the rest of the servers. So there are many, many type of orchestrators around to deploy these sets of containers. You have Kubernetes which I think you might have heard about it. That is very popular, if you know it's like one of the most popular actually it's also Mesosphere actually is used by Netflix and I'm not wrong. Apache Messos is the open source project and then the last one they did try Docker did try to come out with is Docker Swarm. Okay? So these are the few orchestrators so orchestrators are things like they take your container and then they deploy to all your servers. The rough idea of how orchestrator works. Okay? So what do developer use or what do we use before Docker? How do you code before localhost? So for me, I use to code in VMs. Yeah. VMs. Hmm? Yes, so that is going to explain the difference between a VM and a Docker. So basically if you look at VM, this is VM, you have your infrastructure your computer and then you have your hypervisor. Hypervisor is like you can call it like your virtual machine. No, virtual box. Virtual box. Virtual box is actually lies on top of a hypervisor. Then on top of that each VM is a guest OS so you can have Ubuntu you can run windows also on your Mac in virtual box. Right? Then you have your guest OS and then you have all the libraries that you need and then you can run your app. Right? So in very big companies VM VM Ware you can deploy VMs to different servers or so. Then you can spin it up. Okay? So that's one way. This is VM. So what's the difference in Docker on the... So on top of the infrastructure you have the host OS. So right now you guys are using Mac. Then on top of that you have Docker. And then everything else is just the library itself the app. We don't have the guest OS. So that's why in this sense you can see that oh actually to run Docker is about faster, lighter weight because you are removing the guest OS itself. It relies on the host OS to run. So that's why it's a lot faster. Okay? A lot more way to spin it up. So this is the difference in VMs VM and Docker roughly. So if you all have any question just raise up and shout across also can. Okay? Hmm... So what's the benefit compared to a VM? It's actually better density meaning that you can put more containers in a computer than VMs. How many VMs can you spin up in a computer? At most 2 to 3 max. But you can spin out hundreds of containers in your computer. That's still possible. So in terms of that computer and you can put different kind of apps in the computer also. So next faster booting time because it doesn't rely on the guest OS. It relies on the host OS itself. So it's a lot faster. To boot up a container it could be when you run the hello world, how long does it take to run the hello world? That's how long it takes to run a container. It also depends on the container size generally but you will not take more than 1 minute or so to run your container. Whereas if you do a VM in relative you might take depends you're booting a Ubuntu VM or you're booting a Windows VM and it takes a bit longer actually a lot longer. Okay? Better portability also. I had this when I was working in my previous company I was coding an application and then I coded in Docker and then when the time we need to move to Windows we actually can just port this Docker image over to Windows and run it also. So it runs perfectly. No issues. Whereas you can say that for VMs you also can port. As long as both system has a virtual box and then you still can port over the difference I would say is only in size. Because in your VM usually you have 30GB, 40GB an image size at most what I see in these days the highest I see is about 2GB only. Ya. So you can port an image over also. So in terms of that is portability it's a lot easier. Okay? I think that is quite common is when you start to use Docker for development moving forward you will see also the trend of people using Docker to deploy stuff like using Kubernetes that's where it works well with your modern CICD pipeline also. So a lot of cases we use Docker to build using CI to build the image and then using this we deploy to the ecosystems. So this works very well with the CICD pipeline also. It's a bit hard when you try to do with VMs when you try to do a CICD with VMs. You can do it via Reagan I guess you can do that but a bit more tricky a bit more work to do. Any questions? So why is it so popular with developers? Okay. It's consistent across your dev, QA and prod environment. Okay? And recently you heard this thing which is quite common now it's called infrastructure as code. Essentially what you are doing in Docker is also writing your infrastructure. Whatever that you are writing it's going to be infrastructure for your app. So that's why and all these are codes that can be different and whatnot. Okay. So there's many ways to do infrastructure as code. You have other tools like a chef, you have a lot of ways but the key is that your infrastructure can be placed in a version control where you can see the difference you can ensure consistency across all your infrastructures. Okay? So minimum configuration because you are a Mac so you enjoy the minimum configuration. Okay? So when you install Docker it's relatively easy DMG install and then that's it then you have this icon that you run. So not so much that but if you use other stuff like chef, puppet or answer bird that requires some stuff like example for chef and puppet it requires some form of agent in the base on to install this software. Next. Basically if you say that you're running Docker it means that you are taking care of the infrastructure so it's no longer the time when you can say oh I need server with oh I need this server with Ruby installed I need this server with my SQL is the one deciding or building the infrastructure. So a lot of responsibly now I move back to the developer itself the developer that does the application so it's no longer those days where you go tell your IT guys what you want, what app server you should need, what software you should install and so on and so forth. Now everything goes back to the developer. Good thing and bad thing. Okay? You get to expose more. Bad thing is that there's a lot more responsibility on you right now to build your application and also because you are the developer so you should know how your app should be run and what your app should have so that it can run properly also. So now a lot of these are back to your hands now. Okay? Any questions about this? Do you have anything to add Mike? Okay there are configuration tools. So they are like if you spin up servers right? How do you install stuff? Used to be that you go into the server and then you install stuff manually. Well with Chef, Puppet and Server at my own computer I can run this script and then it goes to all my servers hundreds of them and install whatever software they need to access the machine myself. It's an automated way to install stuff inside the servers. Ya. Okay. So like everything in life there's no one silver bullet for everything. It doesn't mean that docker can be used. It can be used for everything but it doesn't mean that it's a good use case to be used for everything. So like everything that we learn good to use, what is not so good to use. Okay. For example, if you are running windows I would advise maybe if your application requires windows like IS to run, you're running C sharp then maybe you don't want to use docker because I don't know how you dockerize windows inside there. So that's also things that you should take note also. Things that you might not want to use it with. Okay. The reason why I say this is that it everything that's a skill is a monitor app is on one end. To use docker it also implies that you might not want to go into micro service way of architecture. So the effort might be more than the benefit to break this app into many pieces to dockerize it to split it up. So in the end you have to weigh whether effort is more than the benefit or the benefit more. So you have to weigh this out also. Okay. And then you don't have a CICD in place. Okay. But in many things whatever application is always good to have CICD in place also lah. Okay. The next thing is you have zero access to the production environment also. Why would that be a problem? Because sometimes you might want to actually that it's not a problem it's more of a troublesome thing to do. Ya. But I know in a lot of cases like our company we don't have access to the production environment also. Ya. So that is more of a troublesome thing to do also. When you want to deploy stuff. Ya. Okay. So some of the terminology that we're going to use when we deal with docker. So the first thing that you always hear it's an image. Right. So that's the first thing that when you encounter docker you always hear oh I have this docker image oh we have this we have that image, image, image. So exactly what is an image. Okay. So an image is okay if you look at the docker glossary, it's actually a collection of file system change. Okay. So basically it records down anything that happens in the file system. It records down everything. Okay. It's a layer of changes to the file system that is stacked upon one another. So that you make this change they'll cache it. Say you make a directory then docker will remember you make this change as making a directory. Then the next step you do is you put in some file and then docker remember oh you put in another file but they remember the sequence. Okay. So it's basically a collection of steps that is made to the file system. Okay. And the image has no state. And the image doesn't change. Okay. So again an image is basically a collection of steps that you make to the file system. Okay. So that is an image. Okay. The next thing that you hear the most often it's containers. Okay. Basically you can imagine if image is your recipe then containers are the cake. So to make cakes recipe can produce many cakes. Okay. So think of it this way. Whatever that you write in your docker image because it steps right make to the file systems they are essentially your recipe. Okay. At the end of it you use this recipe to produce containers which is in this case your cakes lah. Okay. Cakes. But I never go and just copy for internet never go and credit to don't know who works. Ya. Okay next slide. Let's go to the hands on. Okay. So roughly an idea of how docker is. Okay. Now let's go to the hands on. Let's go to exercise 1. Okay the basic docker command you can see it's docker and then once you click on this you actually sees a lot of stuff. Right. So if you notice that docker is also quite sneaky that when you install they pre-install swarm for you. So it's the way to ask you to use their stuff. But it doesn't mean that you need to okay. These are all the commands that you would run or the things that you might want to check to do so that you can see all this here. So some of the commands that we will often use is build. Okay. This is when we build the image. Okay. The next thing we will use is how often that you will use this tree. Okay. Run is to run is to use the recipe to bake a cake. Okay. That is run. That's what we do docker run hollow world. Remember the first step that you all did is basically to run a container using the image hollow world. Make sense? Okay. And then RM is to remove the containers. If you got 100 cakes, you might want to reduce to 50 cakes so you can remove the containers. RMI is to remove the image itself. Okay. So some of this I can leave to y'all to read. But today we will go through the most commonly used that you all have a taste of how is it like. Okay. So next thing so you can use help to, so for example you have a, so to have a, you can go to one command and then there's help. So that will give you a list of other stuff that you can do with it also. So basically this are the stuff that you can do. You can do a run, you can container, you can pause, you can look at the log file, you can do a lot like this. So this is when you want to dig in into each of the commands that you have. Next, you can see your docker version. So RMI is 18.6. I think yours will be higher slightly higher than mine. Okay. So that's your docker version. You can do docker info. So docker info tells you what exactly it is inside here. So you can tell you which. So Kerner version it's basically something that every time when you run docker it runs on this thing called Linux Kit. Okay. So called that OS that you run. That docker runs in. Your operating system basically everything lah. If you want to really dig down into this is really quite complicated. But this is basically the things that you can really look for in docker. It's good when when you are running docker on a server then you want to know exactly what version that you are looking at, what are the information. Okay. Next. So basically we do this again what this command does is docker run the image name. Okay. So when you do docker run the image name what it does is using the image it will spin up a container. Okay. And run. So if you do a docker container ls you see nothing but you do it all then you get to see. If you do a docker container ls basically it says or it tells you all the containers that you have run. Basically all the stop containers. So for me basically I run a few things and then you can tell you when it exit. That means when the container stop. For you, you should see at least minimum 1 or 2. And then when container was created. Then you can see the image. This is the image. Okay. And then every time when you run docker image you always will give you a container ID. Remember one recipe produce many cakes right. But in the IT world these cakes are all unique. They are identified by the ID or by the name. So the names are auto generated. So you get to see all sorts of names on your docker container. Okay. Okay. Any questions? Unclear. Things that you might want to ask. Yes. How what? Sorry. Ah, yes. Good question. So that is where I coming to next. So how do you know what you have downloaded right? Okay. So what do you have downloaded? Okay. Okay. So the next one is docker image LS. So if you do this at least a series of I have a lot lah. But you all should have hello world ni. Okay. So here will tell you basically these are the images that you have downloaded. The next question that you will ask is download from where? Right? Okay. Hold that in mind. Okay. So you download from this place called docker hub. I don't remember the address but it's hub.docker.com Okay. So this is like any Ruby developers um any javascript developers Okay. This is your MPM. Okay. Your gem. Okay. I don't know javao if what is this. Maybe. Basically this is the source of all the image. So like we did run hello world right? So if you search for hello dash world then you get to see this. So I'll explain a little bit more about this. Let me zoom. So things to note is that like every time when you go to MPM or you go to Ruby gem or what so how do you know what is from that company or how do you know what is not from that company or it's from some third party that does this. So official okay. Official is what docker and dos said. This is the official report. The rest is some third party stuff. So if you look at official hello world you click on this and then this is the official report and then basically you see a lot of this and then it tells you the sample output so this is where the image is downloaded from okay. You don't have to login to download an image or you don't have to sign up for that matter. So back to this when we download hello world in this one right there's a few things you can see you can see tag you can actually tag an image in this case so they tag an image to a version number okay. Your recipe you have version 1, version 2, version 3 so you can tag the same thing. Recipe is still called chocolate cake but you got chocolate cake version 1, version 2, version 3 so tag is to do that to tag the image with a version or you can tag it with anything by default if you don't tag it docker will assume and you will always call it the latest okay. This is the default behavior Next you will always have an image ID and this is unique and then when it was created and then the size the size of the image so there are some that is a lot bigger than so there are different sizes one thing to note that when you look at this right you will be thinking it's like if i got 100 image then my hard disk run out of space very fast right then i got 200 okay. So what happen is in every image remember it's a layer an image is a collection of layers so docker is smart enough to say that if image hello world and ruby they share the same layer they will use the same layer so they will not duplicate the layers do you understand what i'm trying to say so this is absolute size of this image but the layers can be shared like recipe you have X right recipe A, recipe B will both have X so the X, these X are shared yes later you boil down to the layers okay so if you want to see the layer you can do a docker i think inspect hello world then that's where you come to that image so you do docker inspect hello world so this boils down to if you have bigger image because this one is only like 18 kilobyte 1 layer but if you do like 1 gig 1 view, you see quite a few layers so these are different layers example would be if i use ruby lah so i do ruby so docker inspect ruby 2.5 can you see the layers this is like your X so if another image sharing the same layer then docker will be smart enough to say okay this layer also put here so this layer is a certain size but it shared across many other images that's why when you look at the image it doesn't, it's not going to tell you to say that you plus all them together is just how much docker is using just bear in mind that at the end of it all your layers all your image are layered okay the layer parts okay so an image has many layers say that this image right now have 1, 2, 3, 4, 5, 6, 7, 8 8 layers and one layer is an image a layer is defined as something that changed in the file system so this layer is a series of commands that happens to change in the file system so docker is smart enough to say that if whatever command that is in this layer another image is also using the same command exactly the same thing the output is exactly the same and then docker will say okay use this layer to be shared with another image so in that sense your size of that image is a lot smaller so in terms of IT there's no duplication for that matter because when I first started this when I look at the docker image I got quite shocked la because if I have a lot my heart really going to run out of space very quickly but it's not this case but if that's a good way to tell your boss you need a better computer then go ahead and tell your boss that you need a better computer so layers remember image are layers so back to here this give you a series of images that you download from docker hub next I think we have seen a little bit of this docker ls so if you just do a ls what it says show me the current active running containers okay right now if you see nothing means that there is no containers running in your computer or localhost now but if you do a dash dash or like I said before it shows you everything okay these are containers that is stop remember okay let's try so we do a docker rm then my container name is called serin Jackson i do this rm i don't know what's your container name it's not serin Jackson for sure it can be something else so docker rm the container name okay so you should see a output of the same container name everybody manage to delete one container okay so to tell the difference right right now to see whether the container is really deleted we run the command again docker container ls dash dash or okay we're seeing the container that you just deleted okay so to reiterate this command this command docker container ls dash dash or is to show you containers that is stop okay but once you deleted the container it disappears okay okay if you look at this basically gives you all the containers dash dash aq okay docker rm container name you actually can do docker rm container id okay or you can remove the container via the name or the id because these are unique like many things there's always one more way to do things so that's why we do docker container ls right we also can do a docker ps it's the same this one also shows you the active containers this command it's the same as docker okay they are the same i think for because when it first started i think it's docker container ls then when they upgrade the version and then they decided oh let's do another one but they want to keep the old one and then you have again multiple ways to do things okay or ps i also forgot but for bad work compatibility i don't know which one can first so same docker ps and then there's a docker ps dash dash same thing it shows the same result which means every time you run it's different and you can expect the result or whichever one any questions on exercise one oh ya wah that is can try that so like Michael say there's another command docker prune system if i'm not wrong prune docker okay so basically this one tells you that you remove all your stop containers because that's not i got a lot right so if i press y it tells that okay so now if i do a docker ps dash all i have nothing okay good tip i can also do oh yes but i won't do it on my system but you all can try you all can try the untact one ya how do you save for example you modify the certain image how do you save it because if you want to do a clearance you need to make sure that the proper image you want to save good question that's exercise 2 ya so that's why we are going to exercise 2 that's the next step the next step is we know how to clear the image but we also learn how to build our image that's the exercise 2 that we are trying to do but other than that basic image container ps okay okay so let's go to exercise 2 i guess you all have to clone the registry first have you all clone the repo okay good okay so let's just go to exercise 2 okay then get to your i don't know if i've clone this oops sorry one second then go to your favorite text editor okay a bit too big can you all see string this a bit more okay so go to exercise 2 okay in exercise 2 okay let's create this thing call a new file and this file you want to call it so in exercise 2 folder create a file name capital D file small f so why do we want to create this file? because by default convention the image or the recipe that we want to build is always called docker file okay this is by convention okay not small d not whatever okay it's capital D docker file okay so the first thing that we want to do when we want to build an image is the first thing we have to ask is what sort of project do we want to build in this case what you are seeing here is a node project in exercise 2 so we want to build a node application okay that is our goal our goal is to build a node application a to do node application so to have a node application the first thing that we need obviously we need a node library so we can do from from okay then we can decide what version of node do we want to use okay so how do we know what version is there alright there is node there is 10 there is 9, there is 8 so this is the good time to go back to here your docker.com look for node and then you'll see oh okay obviously we only want to take the one from the official the reason why you don't take from other people is because you don't know what they put inside there also unless you read through the docker files okay so when you click on node and then you'll see what the shit wow there are so many of them how do we choose what is good what is what so in the world of docker images okay generally speaking there are a few types okay the first type is thus the version number okay you see this one 8.11.3 this is thus the version number then you realise what is alpine, what is on build what is slim, what is stretch what does all this means is the size of the image so when we want to use an image and deploy it to production we want to deploy it to our server we always want the image to be as small as possible so that it is faster to upload, faster to deploy, faster to do everything so when we always want to get the smallest image we always go for alpine okay alpine will be the smallest okay the the fat one is always without any version number without anything so it does 8.1, 8.11.3 without on build without slim, without stretch without whatever so why are there so many different aids because developers they want to give you all the flexibility so you get to choose alpine being the smallest without any word being the biggest so everything else is in between okay so how do you make an image as small as possible right why is there so much different between the size it's because if you go to the most fat one you have other libraries like kerl have you use kerl you have other libraries like kerl you other libraries like basically some monitoring tools some system tools that is a good to have basically the bare bone that need to run that's all so for development purpose or for things that we want to build and try we always want to go with the fattest one because there is other libraries inside that we can use also okay so now you know this basically you can try to okay so now we pick one of the let's pick so many we got nine one maybe let's pick 8.11.3 okay so from here joker from node you specify the image that you want you specify the version 8.11.3 okay so what this says is the very first statement from means when you run this docker file please go and find the node image with this tag okay so this is what we want okay the next thing that is good to have is you always like to put maintainer who actually maintain this image okay so you can put anything you can put your email you can put your name you can put you can put anything you want okay this one has this one is not so much of the docker will do anything to it it's more like when somebody else sees this file then they will know oh this is the dude or something like the author something like the author or if you're going to write a very bad file then write the one that you don't like the name also can because nobody knows okay can so maintainer doesn't do anything it only helps in readability of this docker file okay next let me check exercise 2 okay let's go to the final final is all of work directory okay what is work directory okay work directory is like to specify in this image where's the home directory okay the home directory of this image essentially that's what it is ah so if this doesn't exist then what happen docker will create this for you okay yes thank you can you can actually call this anything you want doesn't have to be app also okay i also forgotten everything already next one is most important one oh ya aha next is you copy okay what does copy do basically is to tell docker copy the current directory of where the docker file is okay so if my docker file is in exercise 2 folder what it does copy everything that is within the exercise 2 folder the same directory where docker file okay so if you have nested you also copy the nested folder so copy from where to where this 2 is inside the container this is on your local host this one is inside the image or inside the container so we want to copy from your local host current directory where the docker file lives into the container work directory call slash ap okay niks let's look at the readme again okay then we do the next important one is to do this run okay so run state please do whatever command you want inside the container okay so those that never do note before this is like bundle install may even build and i don't know what else is this this is basically just download all the dependency so run whatever you want in this case we are just doing mpm install it's to tell the container please run whatever command that you want here okay ah good question so what if you have 10 commands you want to run so this is where remember the layers part comes into the picture you have one layer okay every line that you write in the docker is one layer okay so if you have 10 commands what usually people do is if these commands are related they will put everything in one line so for example i have another one for example another mpm install 2 like that and then if you run another command you do a nn it's just like how you do in linux when you want to part commands you do a nn okay so what this does is you're telling docker please run this command in one layer okay as opposed to run you can do this also it's not wrong it's just that you are creating multiple layers that's all okay and why layers are important is we will go through this later just bear in mind that it's important to always group commands that is related into one line okay what if you have a file then you can run the best script not run the best script then the question is can you break the best script into run commands here ya so we run and then the next step is we do this cmd so what does this do actually so in every container you always want to do something for example when you create a container you want the container to do something either to start a server to copy something or whatever so this is the command that you want to run okay when you start the container what's the one command that you want to run here so if you specify cmd the command that you want to run because they don't accept spaces so you comma then the version so usually it's like that node space dash dash version right but because you can put space here so you put node then comma then the version argument okay so so so you can actually install that extension and you can copy that i think it's the atom and copy it back and it's always similar to this so it helps you to add color code so otherwise you can't color code it it helps you to manage it and then what option to ask so you can do it what's the first option run and cmd i think you just do run node okay so cmd you can have multiple runs command but you only can have one cmd in a talker file okay cmd is to specify the command to run when you start a container so you only can have container is one process so this process what do you want to run it as for right now we do it as cmd okay run things preparing an image and all three registers software that is inside that container image so you run that inside the container when you building that cmd is what run so you do a talker run actually this is the first command you can see that in action later so for example node is one example but say that i want to install a new so usually what you see a lot is cases like that run and then you run app get install wget and then and app get clear cache i've forgotten the command but along that line oh yeah oh yes so it be app get update hmm yes so if i do everything in one it's only one layer so it's the reason why later as much as possible if you see a talker file let's look at a live example think it will be easier to see a talker file each layer is actually cached hmm it changes that line it actually recaches that oh this is not a good example it actually makes more layer usually everybody will put one in one run command but you can see there's also quite a few runs here but the idea is cause like what Michael say you want this to be in one layer i'll show you why it's so important to put this in one layer later when we do the talker file more you'll understand but generally you see they are usually very big runs commands and they are group logically so this one is to install the system stuff then the next one is to install node or whatever so they are group logically okay so right now you are done with your first talker file oh ya ya ya okay make sure you have this then let's build our first talker image so go to your exercise folder exercise 2 so the new command you learn is now is talker build okay so like everything else we need to tag it okay what should we tag it with you can tag it with talker workshop let's call this image maybe node workshop okay then do a dot you need to do a dot yes why the dot the dot is to basically also tell where to find the talker file so right now we are in the current directory so it's to tell our talker hey please build the image with dash key node workshop and where to find the talker file the context so if you do this you will start building there you go okay anybody don't see this screen oh what do you all see and i see the talker file oh i'm in the wrong directory you have to go to exercise 2 okay okay who else cannot find who else cannot see are you in the correct directory i'm not a right user incorrect user can i see the talker oh you sign in oh i sign out can you try sign out and see what happens but actually ten case because when you pull is okay or whatever thing you want interesting if not you could try pulling from another it does so so sometimes it's because the command line doesn't tell it with the demon so in command line you do a docker lock in but you don't have to do that also because when pulling image you don't have to lock in so i think there's something salah who else got issue okay if you all want to go take a break can take a break again because it's gonna take a while ya hmm some finish already still doing okay i think there's a sudden search of people downloading that's why it's like so slow yes yes so you're downloading so you're downloading so right now what happens is you're downloading the node image with this tag 8.11.3 so these things that you're seeing here are the layers inside the image ya ya because remember we do a from part is the first part where you see from and then it understands that hey go and pull the thing in the docker because that is a system library on your localhost this is an image ya so it's a bit different in that sense ya i don't yes unfortunately i don't have a better solution to this we should have use the alpine or something hmm ya ya no i don't think we're using ya lah we're using the fat one that's why ya hmm should i like no lah don't cancel already lah i'm already half with that already it's okay it's this what are we doing we're still downloading oh no still got npm oh shed oh ya how's everyone all your docker build done done anyone still waiting for download or anything okay you should see successfully tag node workshop latest can no problem so once it's done just type docker docker images ls docker images ls you should be able to see that extra container inside your list you should also see the node container inside the list of containers sorry images rather images just type docker docker images ls docker image ls no? do you see this have you done downloading you say do you see successfully tag at the end of the message missing? okay this one where's mine this one this command it's not like programming okay everybody managed to see this ah okay so if you notice that does not what we do docker build dash t and then node workshop right then remember if we didn't specify a tag it always put latest ya it didn't so this what happen does now so if we didn't specify a tag it will does put latest for you if you want to specify a tag you can do it later i'll show you how also to specify a tag it can be something else and then you see the difference in size so from here you can tell that the base image is your 8.11.3 whatever we add on is only the difference that's essentially your mpm libraries that makes the difference okay so now you know how to read the size ya so it doesn't mean that this 2 plus together is one of a cake can finish it not moving you might need to go the alpine way tiya okay so right now we can try to run the container image that we just built so we do a docker run node workshop it's quite similar to the first command we run docker run hello world but this time we are running the image that we just built so when you run you should see 8.11.3 so where does this come 8.11.3 is when we look at our cmd so when we do a docker run the command that the container know how to do know what to do is via the cmd hence the cmd you can only have a cmd one cmd in the entire docker file okay because when you do a docker run this is the command that do this whatever command make sense okay up to here any questions no? okay so let's go to okay so another thing that we can do is we can do a docker run node workshop but this time we want to override the cmd we don't want to keep doing this node version thing we can do it in the command line you can do ls slash app so what does this command do is basically run again the same image but this time replace whatever the cmd with ls slash app okay so if you run this you should see a list of files in the container okay how do you know this are in the container is because in your current localhost you don't have package dash log jason and package.js this one you should have okay these are the two things you don't have okay this is whatever that is running in the container okay so if you do a docker ps dash dash all you can see that now you have two stop containers correct? you should have see okay both running node underscore workshop but they are different commands okay so this is how you build an image using docker build and how to run the image is do a docker run the image name which spin off container okay questions? okay should i do the copy the last time was very slow so so the other thing that we can do is okay especially for java for compile language is that after you compile you want to pull something out for java you have your dotjar or your wall file or whatever so say that now we have we want to pull out the node modules and we want to pull out the package log.json from the container how do we do that how do we pull things from the container into our local host okay so we can do this docker copy so docker cp the container id and then you specify where do you want to copy from slash apps you can copy the node or dews okay and then where do you want to copy to in my current directory so remember you just do docker ps- or you see the container id and then you look at the container id which is the first column on the left maybe you can copy from the first line so basically that's telling you i'm going to copy stuff so it's how you kind of like i've stuck this in the container that i've used before and i want to just copy out in this case we'll copy out the node module folder in another basis there will be a log file that was created when you were generally fouling for example even copy out the result or the log file it's very helpful same thing okay enter yes good question and then you're done right now you should see if you do an ls-a you should see your node module here i only need one a single container each time i run one it replaces each time you run it replace and then no version and then you see how you run your terminal you press okay run workshop okay run again okay run this again okay then buffer ps we did it this is the first time i see this this looks legit this is what the i just downloaded oh dash dash is it is there a difference between one dash and two dash yes oh wow dash dash for a minute i got so shocked okay so right now let's copy the log file okay try on your own package if you want to see you can do the run it then copy it okay copy out the log file of course you can read me okay okay anybody had problems what the what is this what is that oh so cool i say i thought the one slide some shit fighter game okay can copy the log file do you need the name of the log file anybody problems can okay now okay now we move on to exercise 3 okay let's install a web server okay to serve our our html our node stuff okay so right here we can do a run npm install dash g okay the next thing we want to do is we want to say expose 8080 oh sorry okay so again the first one i think this one is quite clear what we are trying to do again run please run this command in the container expose expose is like maintainer like that it doesn't do anything but to inform the developer that this image requires this pod to be expose that's all it doesn't docker doesn't do anything with it but it provides information of what this image pods to be expose for okay just checking shit i don't know because i very quiet expose folder 3000 expose folder 8080 okay suddenly so quiet next okay okay now we do same command oh yes so we have to change cmd to this keep forgetting stuff htb server slash app then please open the pod at 8080 this is the command so now docker same thing docker build dash t no workshop so the difference is you notice that there is word using cache so docker realize that the previous layer is the same exactly the same thing so docker say okay don't need to do this again i already have that layer so that's why you have different layers and that is why in other docker files the run are so big because if there is nothing change it will not run everything again okay so that's why use cache use cache until they notice that where up to date then you install okay so this time we can run this so docker run dash p 8080 so what this do is the same thing but this time we add something called dash p dash p is to tell the docker please open up pod 8080 on the container and map it to your localhost 8080 okay virtual box before this is pod forwarding okay then you get to see now you have available on something something and then you can see and then you get to see to do this okay so the beauty about this is that if you have no node ever install on your computer you still can run node stuff okay if there ruby you can use an image or whatever yeah let's check it out and then run so that's the beauty about docker so it kind of keep your host very clean otherwise if you all have multiple versions you have to use rvm node js nvm so in this way you can have very clean cards so this is your running app okay anybody not see this okay good so next thing if you try do this open the new terminal app and type docker ps see what happens if you're having except docker ps or docker container list so instead of carrying nothing like what we did just now we now actually have one container running so because what we did just started it's not it's not stopped yet so you can do docker ps docker container list it's actually still there so it's different from the previous docker run where if start it does nothing and it goes away so this is what you do because our command makes it linger which we start server so because i call apache so so when you boost it it has something from the main it's just like main this one kin baggage it's just basically auto generator so that it keeps the name unique ya you can get out by doing docker run dash dash help so congrats we have a first image creator and running it okay so oh okay you can ignore this next so this thing that we are going through right now it's good for development so right now say that you want to change something in the source code you can either go to your visual studio change it run the build again then run the container for example if you want to change something in the index my god okay so to do this what you need to do is essentially do the docker build again then let everything run through basically you all get the g's of it then run this again okay remember to stop the container ya okay then you see okay so say that this process is very tedious so there's a way to mau it so this is what exercise 4 is about okay this time we can this one so what this does is same thing docker run you can try also because since you're using mac this is very good to use for windows i don't know windows painful but can be used but very painful okay this is back tick the one above the tab pwd then close back tick okay so what this does is telling docker please mau my current directory to the app directory in the container and also open pod 8080 with this image run it's not docker workshop okay so once you do this same thing but if you change your source code so if you go to your source code and change to remove then if you run this again it reflects automatically so it's like mounting your system folder directly to the container they all manage to do the mounting once mounted, you can change anything in the index html or whatever okay just see that the changes get reflected did anybody haven't reached this stage yet mau it perfect so to escape the container press ctrl c i think if you should have known by this okay so say that now you want to enter into the container right you don't want to let the container run by itself you want to go inside the container so you can run this command the same command okay press up and then it start bash okay so once you do this wait touch on my tag of course i miss out something the most important command dash it i was wondering what dash you must put dash it dash it send for interactive terminal you want an interactive terminal dash it then you mount your folder then you do the port tell which image you want to run and then the bash bash is like the terminal shell script shell then you should see something root at blah blah blah slash apps okay remember we specify our work directory to be slash apps so this is why it fall when you enter into the container it will bring you to your your work directory so this is why it is in slash apps okay whatever you do inside here is in the container you delete stuff whatever is inside the container so it doesn't affect your local host actually right now it does because it is mounted okay yes oops okay if it is not mounted okay so in this case why is it good for because sometimes you want to debug stuff you want to run other commands beside then how do you do that in the container this is a good way to do that okay go inside the container and run whatever you need to run i don't know what version you're logging into the container and you're logging as root okay any questions about here yes tomorrow whatever change you do on your local host will also reflect in the container and vice versa so right now here if i do a touch test.txt i'm creating a file in the container but if i look at here i should have the test.txt whatever you do in the container reflects yes that's because you mount for the if you don't mount anything you will not see anything on your local host can yes correct yes rather than going through the build process build the image or this so you don't have to go through that process every time you change your source code can okay alright to exit control D and then now you're back to your local host i mean your host computer okay so for more stuff you can read the reference here okay exercise tree okay maybe 15 minit 2 litre okay finish at 5 can yes home of pro because 2 box then you need to map folder in the virtual box no there is another thing if you do that and then you're in WSL but you're not in WSL then you need pwd to lower oh shit behaviour right just happens at that time oh actually it was like wow i think that's straight ahead wow everybody on map was like good i don't know my first time here i'm sorry i cannot help you oh i don't know leh he's the staff right i can you can ask him sorry i think she needs to get out of the building yes you got a mouth wait where are you now exercise too are you you need what do you need to do oh it's a back tick oh my god ah okay so another thing is that there's some folders that you cannot mau usually you have to mau in your home directory so right now you're in application mem directory so you need to in your home directory it works so there's some permission issues docker because you definitely don't mau your system files into the container also so you need to okay let's move this let me close this i go up one layer can we put this in your can put exercise off them then go out on another layer sorry i don't know how to use and then put this one can we put inside your home folder where do you want to put and you got 180 mau but i overwrite but actually it's like because my memp is under my home directory your memp just on the one you say you map it directly into wah so fierce okay i see wait you mean you map everything inside here inside your directory no lah this one only got here intro to docker workshop okay overwrite okay maybe i i don't know do you have something let's put this as few one okay then where's the other open this again and drag this one in okay so now wait why is it a oh you need a copy okay how to okay then right here you can't go to your home directory docker all intro docker workshop exercise do okay then here you can run the command game docker there you go okay so it means i straight away do yes you can do when you map when you map it directly you go inside it directly but you always automatically do yes yes so that's why um it's actually a security floor when you try to mount the system root because then docker has no difference of name space so your root in the container also is a root in your your host i think that's why i think that's why i think that's why i think that's why i think that's why i think that's why yeah then there's also why if you have both also same name then the one is another story but the one you're okay it's a lot more complex yes still got sorry to get this the trouble is the fear oh you cannot i see docker looks legit pwd bring the this one this is going to cause a problem so inside here pwd.2 lower oh but inside here pwd.t inside inside the grave to lower it has to be capital T capital L okay okay capital T interesting capital L no underscore okay W.E.R brackets it cannot substitution line it runs it runs and then but interesting you running in a volume different volume docker requires how directory to be okay interesting also your work is in one volume then your system file is in another volume yeah system file is the main volume then i work file separate one that's that's a command that you have to do in wind and hole yes so going back to this slide when not to use docker and do not have CICD in place because if you don't have CICD in place you can push to the registry everybody can push the registry then how do you know which is the latest then when you do the build process you want everything to be automated so sometimes people might change the build process so you are saying that if you use docker it's not a must but it's a really good to have because if you don't have CICD in place the next thing is you can push to the registry say that you push one image then i push another image so if you all name it note underscore workshop latest so which one should it takes just one person is maintaining ah if it's one person if you're the only developer in the team that runs this hole then it shouldn't be an issue but that's when you have more than one in a team that could be an issue unless you can coordinate really well between team members it's a good to have but it's just more like you'll be quite dangerous if in a team you don't have this in place so so so basically to maintain the local file you can check in to get yes then it's faster in linux it's it's more convenient in linux as compared to windows because of the ministry because actually the underlying docker requires a lot of linux tools which empowers docker so that's why windows when you want to run windows what they do is that they actually run like a virtual box then put the container inside the virtual box then the window user can see is that way la but if you're running Mac there's no issue you have colleagues that use windows is it there's one that use windows ah but windows a bit more tricky can work la doesn't mean cannot work still can work so in terms of performance does docker run faster in linux system than mac and windows does docker run faster in linux system then you're talking about does development purpose or production purpose development purpose development purpose ah i don't know but development purpose ah i think for development i don't think there's a lot of difference la because the container is almost agnostic to what you're doing it's just how you're setting up the container that becomes a bit trickier but the container itself is fairly agnostic so anything you run within the container should be fine it's depend on good or laptop is not really what voice you're using the windows found system performance is poor but but that's a very good question yes how to link everything together yes that's a very good question so in the world of docker that's where you have to spin out multiple containers and then link them up together ok um ok maybe i'll explain to the class no no for sure no 3 ah 3 ah ok ok then i faster start ok so somebody ask the question what if we have database and what we have other requirements right because when you run node you don't only run node per se you have your database, you have your radius you have whatever whatever right ok to begin with ok i can share my experience when i first started learning docker what i do or what my colleague, my ex colleague used to tell me do is you install everything in one container first get used to docker first ok so you have your node your node image right you can go inside there and install your database whatever everything in one image so everything work as if containerize in one one ok so that's a good way to start ok and that's a good way to learn to get yourself familiar with more docker stuff ok use the run whatever whatever but after you are familiar with it you should move out from this kind of behavior to different containers you have node running in one container MySQL running in another container Radis running in another container and then you link all of them up ok so that's the angle that you are looking forward to but to make it easier for the start you can put everything into one image first ok that's the journey i took or you can jump the gun and split menu also but the angle is to have every service as one container the reason why is also good because once you have every service in a container especially for your web part you can skill easily i say there are one three containers and then i can skill the three web containers out but if you have everything in one container how you can use skill you cannot skill because it's everything one the rule of thumb is that each container should only run one process one process which in this case one container for web server one container running full spread one container running Radis one process per container ok so in exercise 3 we are going to touch about touch a little bit on can we link containers together it's the pre have you heard before docker compose heard of this term or not docker compose is the angle that you want to go for where you can spin up multiple containers and link them up altogether but what exercise 3 teach you it's the underlying of docker compose what actually docker compose is using actually docker compose docker compose on top of docker so what exercise 3 is to teach you what is the underlying core of docker compose ok so now obviously the first one we go to scenario one is you want to make your containers talk to one another like your node.js have to talk to your MySQL so how do we do that by default docker has this thing called docker network so if you are do a docker network ls and then you can see a lot actually docker network ls so by default docker has essentially 2 or 3 3 3 type of network you have no bridge you can have a network bridge you can have a net you can many type of network so essentially by default docker use bridge it's a way to build networks together next this time let's run a postgres you might take some time to download i should go through this first before giving you other break so now let's run this you all got the command in the read me exercise 3 good question let's see docker for postgres ah yes you do have a skinny version okay 10.4 alpine okay let's try that 10.4 alpine alpine h is it okay moment of truth oh still so big okay while this is running right i can explain a few things you see dash E dash E is a way to tell docker please pass this environment variable with this value okay so when you run a container you can pass in environment variables and say that we do want docker to randomly give us a name we can do a dash dash name equal to PG then after that if you notice there's a command called dash D dash D is to tell docker please run it in the background as a demon have any of your downloaded finish already no no yeah okay so right now if you do a docker ps we should see this the postgres image running that's out of curiosity what's the image size for this oh it's 72 mag only not bad as compared to the fat one it's 234 mag okay so that's a different between alpine and fat version ah remember the other time when Michael was suggesting do the prune okay when you do a docker image prune or docker prune image either one of them it will remove things like that so what happen is why you have none none you all should have some of this also actually if you do a docker images okay it says that because every time when you do the docker build node ah docker build node workshop every time you build one it will give you a new image id then previously you have the latest right so they will remove this tags and give you the latest one so essentially this actually your previous version of your images but you can only have one image name and one tag uniquely across all okay that's fyi ah then you do the docker sheet prune image let me try ah i don't know i don't remember the common yes warning please you remove all dangling image yes does it not work hmm i'll get back to you why the prune is not working ya that's where use help remove oh oh no not all unused image if you need the command i can give you other command i have a shortcut but this one later okay let's focus on the i'll get back to you on the thing okay so you all should have this running do you all see docker ps you all see this pg oi okay so now what we want to do is every time you run docker you have a container ip address okay to grape it basically you do this the go and look at the readme copy docker inspect you look at the then you paste the container id and then you basically grab for this value call ip address okay so right now you have ip address of the container so let's try to talk to the container okay to talk to the container we can do this so docker run again docker run dash it busybox is another image name basically okay and then you ping ping what ping the ip address wish oh s**t but it's very small very small this is damn small very small don't worry okay so what you're seeing right here is basically we are running another container talking to the pg container using ping okay so when we can ping each container means that these two containers are actually on the same network get it okay so this tells you that basically when you run anything docker containers on your local host these containers are all in the same network okay if you run another node or another content on another image they are all on the same network so essentially all of them are able to talk to one another okay but the troublesome thing is there's no DNS resolution basically if I want to talk to the container I need to know the IP address without the IP address I cannot talk to the container but it would be good if I can say talk to container pg rather than the IP address there's no isolation means that whatever I spin up in docker all the containers are on the same network what if I want only these containers to be in this network isolated from the rest how do I do that okay so basically we need to use this thing called a user defined bridge network okay that's to sum up through all these are basically background so if you auto-use docker compose you can go through this also but it's a pain but that's for knowledge purposes so right now let's create the test network okay docker network create how to see that we have the network is docker network you should see okay then we can stop the previously run container so docker stop pg and let's remove it also docker remove okay so docker stop docker remove the container so right now we shouldn't have a container running okay this part everybody know what we are doing okay good okay next time the same container so docker run the environment name the name of the container but this time we add the test network okay we are linking this container this container to this network called test network okay and then we run the shit where is it what's the name of the content the one that I built okay so 10.4 so basically do this done so at this point everybody understand what we are doing again i clarify run the use the environment variable the name of the container but this time we add something new is the dash network we specify the test network okay the network that we just created okay anybody not following yet then this time we can run the busy box again so this time when we run the busy box we also have to attach the busy box to the same network right because we want busy box and the postgres container to be on the same network okay then we do a NS lookup test net hmm oh but they give me the ip address i don't know why there's no answer but but you notice that it does give me the ip address correct so what we did here is instead of finding the ip address out like what we did for the container ip address this time we can just do a lookup to pg right so now we have the the domain name called pg and pg maps to this ip address so that's how we going to link containers up next time we declare the container that we want to link to via the name the name of the container okay okay so basically there's other a lot more docker networks that y'all can go and read about if you all want to explore the different parts i have a ex colleague that used to run that can play multiplayer on docker containers across 2 different host i forgot how he do it but he managed to do it that's where he deal with all this network stuff but you can do that also okay unless you want to dig in and see how it does okay next thing so every time when we run a container okay it's when you run the container you stop it oh okay actually we got example okay so let's say that you run this okay right now again we run dash it interactive terminal we name it call testbox then busybox is the image sh is the shell and now we are inside the container okay in the container we do a touch test.txt okay so basically we have a test.txt and then now we control d to exit the container okay if you everybody following just want to check ask i am going too fast okay so this time we start the same container that we stop okay we start and then this time we go into the container so this is another way to go into the container when we have a running container and then we want to enter into the running container we do a docker e exact dash it the name of the container okay and then we do a ls so right here you still can see the container right you still can see your test.txt that means whatever you create in the container when you stop it and then you start it again whatever you create is still there okay this point you understand what is the default between you stand when you are mounted when you are mounted when you are mounted it means that you are mounting your host into the container but what happens here is we went to the container and create a file put inside the container yes this test.txt is not in our localhost at all so that's what we do mounting is you bring whatever stuff into the container or vice versa whatever the container has you also put it into your localhost but this one is a one way traffic essentially so notice that the thing is still there but if we delete the container everything is gone make sense right everything is in the container but what if we want something to persist across whatever container that we create a good example would be you want to spin up database you cannot be always using the same container what if your computer crash then your container gone or your data gone you want it to persist somewhere else so that's why we use this thing called docker volume okay okay so to use docker volumes okay this is managed by docker okay it's meant to decouple the host and the container so you can basically you can use if you are azure you can use azure but if you don't have then use your own okay and then it's by mouth it mouse one of the container into a folder that's managed by docker so you don't know where it's being mounted to you can specify or you can check but docker manage this for you so when you specify a volume it creates a volume it mouse the container to the volume and this volume is somewhere in your localhost so that even though you restart the computer you do whatever la the data will still be there okay there's actually 3 types of volume okay memory i don't this is only for Linux only la okay it's good for containers that runs a lot of secrets that once the container or the volume is gone or once you kill off the container the volume will also die together also okay so to create volume we can do a docker volume create so docker volume create the volume name okay you see i got quite a few la but okay you should have one called test volume so if you so you have a test volume then you can't inspect the volume if you really want to know where it is your mouse point this is on your localhost okay so if you really want to be inner about it there's a read only or read and write whatever access you can set to the volume also if you want to la okay so this time let's maul the volume so again docker run dash it remember last time we do the backtake pwd so if you do a backtake but if you specify the file path but if you specify the name of the volume that you created then you maul that volume so you maul it to test app so what is dash dash rm dash dash rm means that once i exceed the container remove it also because right now to we exceed the container it just stops right but it doesn't remove so dash dash rm is to say that please remove it also okay so the rest is quiet okay now we go to the app okay this is the place that we maul right maul the volume to slash app okay and then we create a file okay then now we exceed wait okay oh i press too many times already okay so basically now i don't have the okay let me stop it i think this is another busy box hmm anyhow it's still there but i don't know why it cannot oh it stop okay so the next thing is because we keel off the container already right supposedly everything is gone we want the data back so we can remount it so basically docker run again dash it maul the test volume to the app and then show me whatever is inside the apps folder okay that should have a test or text so that's how you persist data across containers okay which will be very useful when you need state-full stuff like your database yes oh this is a new content this you are running a new one right yes this one is when you run this command you spin up a container yeah remove whatever that you just started okay so volume network dns the name of the container okay so using by maul is usually your PWD so one is you can maul your own localhost folder one is you can maul the volume itself you create a docker volume and then you maul it okay there's two different way okay so take note that if there's an existing file in the container it will be hidden away okay this will only be good if you need to populate stuff into your container immediately when you want to maul stuff so let's say that example you have Postgres right essentially Postgres is a folder somewhere in either slash var slash data if you take this file out then you want to start a new container you can maul this thing into the new container so that's also how you move the data around between containers or you want to pre populate your new database with data that's also one way to do it okay okay that's nice so basically exercise 3 is a docker compose is going to use so i'm not going to go through exercise 4 but essentially what you need to do it's this okay very quick run through it's volumes right okay you can maul your volume you see this is what we are doing is we are maulting the data into the container Postgres data that's how we populate data in you open what ports please go and open this port ports you all should be quite familiar with please pass in what environment variables because when you start a container sometimes you want to pass in environment variables okay so in running Postgres the prerequisite to running the container 2 environment variables basically the user and the password to lock in to your database and then this one is running your image command is remember you have the cmd remember we build a docker image we have the cmd this overwrite that image cmd okay then depends on means that please spin up my database before you spin up my web that's it so there's a sequence okay then environment variable okay and basically this thing called docker compose YML will spin up the networks so in your web you can call db slash 5 4 3 2 and then you will call this db you know you all have a database url you know database url shit so basically database url it's a variable that you need for your web application to connect to your database ah so it's a url i think go no ya so it's a with the username password then the database name ya so basically this is that connection string yes quite connection string so you can try this at home good luck so ya just create a new file for docker compose or YML so all the things that you been doing in command line all the like expose this part command line can now exist inside this compose file which is a very declarative way and you scroll down for now you yall need to just run double compose up and then here we have 2 containers and actually making them talk to each other and you just take a check that work which need to get address each other just by the username in this case db so in this case db there's a whole bunch of instructions how to set your database up to start and basically this is basically running in the Rails application and actually you have a Rails application running and you have 2 containers 1 container with Rails 1 container request postgres and then basically put the Rails container will just talk to the top of your container find database fully running Ruby and Rails environment just in containers and you need to do anything on your local machine so it's something interesting like what you did just now with node you had to load running on your machine without even having to install node on your stack so you can find these trees on your own because it goes all the time of course you can still hang around a bit longer it's very fast so if you hang around you can do it but of course then again i'll never get that very good oh ya best is go home and try if you guys have any question about exercise for keeping us on facebook group or on stack group most of us on stack group we have a stack group thank god