Docker Containers for Beginners | Dan Tofan | Skillshare

Docker Containers for Beginners

Dan Tofan, software engineer, PhD

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
6 Lessons (31m)
    • 1. Introduction

      1:32
    • 2. Containers vs Virtual Machines

      2:19
    • 3. 'Hello' From Your First Container

      6:57
    • 4. Create New Image

      5:42
    • 5. Link Containers

      13:28
    • 6. Final Thoughts

      1:27
11 students are watching this class

About This Class

This class is for software developers who want to start learning about Docker containers.

Docker containers are a tool to solve 'it works on my machine' problems, which refers to lack of reliable deployments and configurations across environments.

This class is also a step forward to understand two current major trends in the industry: DevOps and microservices.

Here is what you will learn:

  • Differences between Docker containers and virtual machines
  • How to install Docker and start a Docker container
  • How to create new Docker images
  • How to run commands on a Docker container
  • How to run multiple linked Docker containers using docker-compose

Prerequisites

  • Basic familiarity with Linux command line (such as folder navigation and writing commands to command line)

Transcripts

1. Introduction: as developers, you'll heard the expression. It works on my machine, especially when the application refuses to work in a different environment. Imagine how much air for me is to be span to troubleshoot a situation when you reach an application works on the developers machine, but not in a production environment after spending much effort and frustration. Typically, the root cause of such situation lays in south till differences among such environments, such as different updates or library versions or configurations. So what if there were to standardize the deployment of an application of course environment so that old dependencies are included? What if we can not only reduce costs by avoiding It works on my machines in arrows, but also by using computing resource is more efficiently. Hi, I'm Dan. And in this course we learned the basics of daugher, which is a tool that souls These problems Learning about docker containers will also help you understand Mawr about develops on micro services at the end of these course. After watching the videos and doing the project, you will know the following how to run docker containers, how to create custom new docker images on how to run a link. Multiple 2. Containers vs Virtual Machines: So what is the container? Containers are related to virtual machines. Both were it'll. Machines and containers offer applications the illusion of running on a separate machine while actually using some smart approaches to simply run on top of a real physical machine . Still, there are important differences between containers and vehicles machines due to their underlying technologies. Very little machines run full guest operating systems. In contrast, containers offer brutalization just for one application, including its dependencies, while sharing the same operating system. This means that containers share a lot of resources, while beautiful machines share fewer resources. Thinking of containers and beautiful machines, we can use an analogy with apartments and houses. Containers are like apartments, and beautiful machines are like houses in consciousness houses. Apartments share more infrastructure so you can build more apartments on the same piece of land. Overall, the right three key differences between containers and people Machines First Dance City. You can run mawr containers on the same harder, just like you can build more apartments on the same piece of land portability. Since containers need less disk space, it's much easier to move around a bunch of containers. This makes easier to deploy and upgrade applications in containers, since you can just deploy your version of a container, which in its less time to be transferred over the network. Compared to transferring a little machine, which also needs a copy off their operating system files and third boot time. It takes seconds to start a container because it shares the operating system off the host on which which has already started. In contrast, beautiful machines need to start a fresh new operating system every time it's turned on. Next, lettuce stole docker and run a hello world container. 3. 'Hello' From Your First Container: Hi. This video, I'm going to show you how to install Docker and create our first docker container. So for this week are going to first create the new server? Um, using a cloud provider called Vaulter. Both are, and this allows you to select greatest server. So I'm going to choose Boom, too. See which ones? So 16 04 So that's stable. One 17 is more recently released and might not be that, uh, stable. Okay, so, no, it's already installing. It's important to note that the steps I'm going to show you, I'm going to execute them as the root user. This is not something to be done, uh, in a production environment. So there you should have multiple users know, just run everything from the refusal. But for the sake of experimenting for the sake of playing a bit with with docker containers on running a ripping in a throwaway virtual private server, it's perfectly fine. Okay, so now it's installing. Okay, until take a few more seconds, I guess we can see we already have. Might be a dress that's try to connect with a necessity client. Let's connect to these these new server. Okay, so indeed, the server might still be installing, but we can. We already have an idea. Dress Faried and also connection leaders. We have the i p. Address here, user name and password. So I'm going to copy this password and use it, you know, in the ssh client. Okay, so here we have our new sir reversal. That's check. Piece is this was I just recently started. So now let's go over the steps to install Docker. We're going to Seoul Docker community addition. There is also an enterprise edition which we won't look into now. Okay, so these are some steps for some older worsens off boom, too. And we're going to install install it using the repository. So that's doing 80. Get update. Okay, take some working configuration steps here. Note that we're since we're already running the root user, we don't need to add, so do in front. Okay? Some more stuff, All right? Just told here, please know there is also little minus at the end of the command. Without that, it might not work. Okay? It's added. Now, let's do the step to verify way Have the keep. Okay. No, Let's had the repository Okay, Now do another update already. Randy's command before. Okay, so all looks good so far? No, Let's stole Dr Community Edition. Okay, You can see it takes about 100 mega disk space. So now we basically have a beautiful machine. And on top of this beautiful machine, we can run multiple docker containers. That makes it quite a great the interesting. Okay, so, no, we can see that gave the final step. We can verify the doctor Communications, it's told. Correct with Dr Ron. Hello, world. Let's see that works. Okay, so let's go back a little bit. Over what? Uh, what was displayed here? What happened here? So please asked it to run. Hello, world. Then it's OK. Unable to find this image locally and is going to pull this image from from a library somewhere. Okay, the pool was complete. The problem. It was a very small image on the status. Okay. The new image was downloaded on this. This is the part. This is the actual hello world. Hello. From Docker. We have some more explanations. It appears that installation is is working correctly. So all this is, uh, its, uh, good news. Great. So that's our first step. That's our first docker container which we executed. Let's see what's next 4. Create New Image: In the previous video, we Ran our first docker container, which displayed a hello World message. Have the doctor Ron in the world and we had a doctor message. Sorry, hello from Dogger displayed. This was useful to see that the installation work well, but in practice makes more sense to run containers with custom functionality. This video will create and run our own custom container. So how can we do that? To create a container, we need so called docker image, which is basically a template or recipe from which we can create as many containers as we want on this machine or any other machine to use an analogy from object oriented programming. Docker image The images are two containers. What classes are objects in both cases, the re some template image your class right which gets substantiated into something more concrete container or object. So where can I find such docker images or templates for containers, the reeds, a docker store and we can search, for example, for the hello world. You mean that we just ran? We can't see it here. It's an example of ah, minimal, very small doctor English. Very small docker container. Okay, And we can also search for other other images. For example, boon to, uh, the res. The reason will do image Over here you can search even for ah PHP docker image or my a skill and even various other images that we might need. Okay, so we ran. Hello, world. So now let's run a different a different image. So let's try. We've docker run. Uh, let's see. Okay, if the Buddha image was not there initially, it's going to be pulled. Okay, so now it's food. And it ran and exited immediately Makes sense toe run it in an interactive terminal to see the the command line. So we used the arguments minus I t and then at the end bash. So let's see this one. Okay, we can see that we're on other the root account in a different on a different machine. So here we can We can do anything we want. I don't want toe just display something just because something we can have it here. And then we can exit when we no longer want toe toe be connected to these computers. Okay, so that's the way to run a to run a container next step. Let's greet our our image. So I need to create a file which by convention, we can call it. We should call it docker file. But we can also use other names. And here we can specify from which image it should be based on, just like inheritance in object oriented programming. So let's no case we wanted to start from a boon to, and we just wanted to run a very basic commands. Pickle Hello from my first. Okay, so we write this file, like, under year. We created this. Okay, so now we are building and you a new image from that. Okay. And now we have this container and weekend. We're on it easily. Her Ron. The name for it is Is this by these hacks based name 93 e and so on. But it's enough to justify the 1st 3 characters. Okay? And it's red. So that's it for our first docker container. We created a new image from this image. We build it and then we ran this. He was next 5. Link Containers: think about the website, which Jess has a Web server. The database, this website It's a container for the whip server, another container for the database and that, of course, another connection between them. However, larger websites and applications have more complicated architectures, which are composed of a lot of very small moving parts which you won't get get deployed different speeds. Here is an example. Netflix uses such an architectural style, which is also called micro Services. So let's get a taste of how to Lincoln Dinners, which is a first step toe. Words Micro services. I will show you three things in this video how to install docker compose, which is a tool to drink containers, how toe link to containers and how to check connectivity between containers using the ping command. Okay, so we are connected to our machine when we already have. I took her told okay and we can see some instructions to install it over here. Okay, so docker compose can be stolen multiple machines. Mac windows looks. We'll look at how to install it on our looks machine that we already have their So let's just copy these command the pseudo parties optional since we are already route. Okay, so no, it's downloading. It's just an executable which gets downloaded. Okay. Indeed, it makes sense to check and see if this is really the latest version. But anyway, it's pretty recent virgins are no problem for us. Okay, so let's make it executable. Okay, then. Tried composer version command. Okay, so it seems was told successfully. Good. The next Nets try toe run on this command, so use docker compose with a big example. The idea is to create to containers have them run at the same time. So first, let's look at our docker file. Okay? Docker file that used We're going to use the boot image instead of hello world because the images more complete compared toa hello world. And instead of just anchoring the manage, I want to install the image I want to install being program. It's not included by the four, So we need to run this command first update, then still the package for which contains being command. So close exit save exit. Okay, so we have no a docker file. Let's try to run this docker. We need first to Billy. Okay, so, no, I have it built. Now it's running. Yeah, best that's check if we have that being command. Okay, we can use being so it seems to be ready. Okay, So in order to run Docker compose, we need to greet a docker compose filed. So the same situation is with the docker file. It's a name which is used by the fold. But if we use some flags, you can also specify different the final leaves. Okay, so this is a new file and he reads the tax for wheat for specified the version of the specifications so we can find more details about these in the Dr Samples reference for mint here with my services important here. Don't use stamps. Just use Spacey's. So let's call these my Web server, put a couple of species and then use this command toe indicate to eat that it should just use a default docker pilot. It finds over there, just build on. So that's basically the how this container is going to be built. Okay. And next we need to give it a certain command so that it won't exit off was suddenly by default. It's just exits. So let's see that. Let's see that in actual for So I have my Web server, and I have my client for simplicity. I'm going to use the exact same docker file on that it. So let's see how these rights. Okay, so docker compose. And then, uh, give it to the up command perimeter minus minus build. So that builds every time the doctor images. Okay, so we saw that the reserve, uh, route Mike, my client, which is built on my web server, which also gets beaten. So lesson some modifications over there. Okay. I still love my client. Let's call it my date of its okay. Lets try again. The doctor composed up. Okay. Now, a problem that we have here is that so the contingents are created their started, but then they're extinct immediately. So we're going to do a little trick so that instead of exiting immediately, they keep hanging over there that they're running in the bedroom without doing anything. Really? So just this will help us to connect to these containers Ransom being commenced from one to the other. Okay, so no such file. Let's call it this Will. This will make the container just to keep running Okay. Okay. Lets see. Okay, so now both Malvinas are running, but nothing, nothing really is happening over here because Canada open that. So if we hit control C going toe, stop. Stop them next. I want toe, actually connect toe each of these containers and check connectivity to the other container . So let's play a bit a decision like that. Let's check if there is any Cadena which is running. We see this one. Let's move it. So not it's 9 to 7. Okay? Yeah. Okay. Make a force. Okay. No more running docker container. So next I'm going to start. So, Dr Compose O minus, minus built. Okay, we have the running. Here they are Route my Web server route. My database. These are the containers that that we have already running. So let's try to connect to these. Occur. No run. But exactly because it's already running. I want a term, you know, on I want to connect to my Web server Run bash on it, but so I can't see my web server. Is we specified in service? Needs to be called. Who? My whips Server one underlined. So these little things really the command you see it's running. Uh, that's what is running over here. We see the tail minus f. No such file command with P i D Process Idea one. So this is the main process which is running here. And now Let's try to being my data. So you see, we're using the exact same name as specified in the darker purples. Why, okay, and we have have another connection to it. Great. So me check now that we have another connection from this Web server, toe the database. Now let's check in the other way around, instead of running from the Web server that's running from the database and in the database that's being my whips server. Okay, and it's working great. So now we're done. We've seen how installed over composed were linked. The two containers using these this docker compose file my Web server, my database. We use this trick with trigger to make the container keep running for a while so that we can run that command. But of course, when using it in practice in a more yeah, production away into the environment course we need to put the actual Web server, we should put an actual database over there and do useful things. This was just for the sake of experimentation, just for the sake of learning. But once you have these much small little machines up running, of course, put the useful stuff in it. Deployed and 1/2. Make your application run. 6. Final Thoughts: Congratulations on getting this far in this course you learned the following four things. The first, the three key differences between containers and beautiful machines, which are density portability and boots Time. Second, how do you stole docker? Run a docker container third ho to create a docker image by running a build command on a docker file. And fourth, how to run a link. Multiple containers using docker compose the project helps you recap the commands using this course and encourages you toe play around and experiment beyond what was covered in the course. The skills that you learned from watching the videos and doing the project are critical for solving the IT works on my machine problem. Furthermore, you also made a step forward on understanding and getting experience on to current major trends in the industry, which are devils on micro services. In future courses, you get the chance to make even further steps, so follow me for staying after date on them. Thank you