Udemy

Docker Containers vs Images

A free video tutorial from Richard Chesterwood
Software developer at VirtualPairProgrammers
Rating: 4.7 out of 5Instructor rating
7 courses
142,217 students
Docker Containers vs Images

Learn more from the full course

Kubernetes Hands-On - Deploy Microservices to the AWS Cloud

Use Kubernetes to deploy a Microservice architecture. You'll deploy, manage and monitor a live Kubernetes cluster.

28:31:23 of on-demand video • Updated May 2024

Deploy containers to a Kubernetes Cluster
Run Kubernetes in AWS using either EKS or Kops
Monitor a live Kubernetes cluster using Prometheus and Grafana
Analyse system-wide logs using the ELK Stack (ElasticStack); Kibana and ElasticSearch
Handle Alerts in a Kubernetes cluster by notifying Slack Channels
Understand how Requests and Limits work in Kubernetes
Use Kubernetes Horizontal Pod Autoscaling
Configure Ingress Control on a live Kubernetes deployment
Understand Kubernetes StatefulSets
Integrate Kubernetes with a Continuous Deployment System (CD)
Use Helm to Manage Charts and to Dynamically Update your Kubernetes YAML
English
Instructor: There are two big concepts in Docker, and those concepts are the containers that I've mentioned before, and images. To be honest, in the last little speech I've done, I was sort of mixing up the concept of images and containers. It is kind of important that you understand the difference between the two, especially when you start working a bit later on in Kubernetes. For me, really, it's images that are the most important concept. An image is a definition of a container. You can think of an image as being a binary file that contains all of the software and things like environment variables, and general settings that the container will need to run. Let's say I'm a developer, and I've been tasked with building a new website, and I have decided to build it using Tomcat, NGINX, and Java. You don't need to be a Java developer to do this course. I'm just using that as a working example. It could've been Python, it could've been Go, it really doesn't matter what that is, but I can tell you, as Java developers, we tend to build these things called WAR files, which is an entire website sort of zipped together into a single file. If I were a developer delivering this website to somebody else who's maybe in charge of deploying it to a server, I'd probably give them the WAR file, but I would expect them to configure Java, to configure Tomcat, and to configure NGINX, and they'd have to get all of that correct. The difference with an image is, I, as the developer, can package everything that is needed, every single dependency required, to make that application run. The idea then is, I can pass the image across to the deployer, and they just have to run that image. When we run an image, now, an image is quite a big binary file, but when we run that image, then the running image, we call the container. That's the difference. A container is an instance of a Docker image. Now, one of the really great things about the Docker ecosystem is that, when we've built these images, we can publish them so that they're easily available for other people to use. At the time of recording, the most popular place to publish images is this site here called hub.docker.com. If you do my Docker training course, then you will create for yourself an account on Docker Hub, and you'll be publishing your images, but for this course, what we're going to be doing is, we're going to be using some images that have already been published. This is my account at hub.docker.com, and you can see here that, well, at the time of recording, anyway, I've got five different images, and any developer in the world now can take these images, and they can run them as containers on their own deployments. I think a great way of demonstrating Docker is for you to get some hands-on experience. Of course, the first problem is, if you're new to Docker, as you are if you're doing this section, you have probably not got Docker installed. You can very easily verify this. Open up a terminal window. Doesn't matter if you're on Windows, or Linux, or Macintosh. Type the command docker. There's a very good chance that it won't be able to find a docker command because, of course, you haven't installed it. Now, it might be that you do get a response from typing the docker command. Maybe you've installed it in the past for some reason. If that's the case, then stay with this video, because I need to show you how to run the Docker server. That's coming up in a couple of minutes, but if you're in the position where the command is not found, of course, you're going to need to instal it. I think it's fair to say that Docker is probably a bit easier to instal than Kubernetes was, so you've gone through the pain already of installing Kubernetes, so I assume this is going to be relatively straightforward for you. You can get Docker from the URL docker.com/getdocker. There's two editions. There's an Enterprise edition, which is sort of Docker trying to create a commercial environment around Docker, but there's always going to be a community edition, which is free, open source, and is production standard. Don't think it's in some way a cut down version of Docker or anything like that. It doesn't have some tools that the Enterprise edition has, but there's nothing wrong with the community edition. They have changed this quite recently. You do now need to follow this link to get Docker from the Docker store. Everything has a store these days. Follow the link to download, and choose your operating system. If you're on Windows, and I will follow the Windows link here, it's exactly the same story as it was for Kubernetes. If you're on Windows 10 Professional, then you will download Docker for windows, Docker Community Edition for Windows, using the link here, but if you're on a previous version, and I am, I'm on Windows 10 Home Edition, then you need to follow the link to Docker Toolbox. For Macintosh, it's a similar story. I'm just using a caption here from my previous Docker course. If you're on Mac on Yosemite 10.10.3 or above, then you will get the Docker for Mac, which uses a native virtual machine environment. If you're on an older version, then you're going to be getting Docker Toolbox. Now, once you have gone through the installation process, the difference now should be, when you type the docker command-- I'm going to do a video edit here because it's taking a long time for me. It's clearly hanging. I did eventually get a response, but it did take a very long time to respond. The reason for that long pause is, Docker was trying to connect to the Docker server. The idea is that, on your local computer, you have a daemon process running in the background that is doing all of the Docker work, and you need to have that running in order to do any work with Docker. Let me show you one of the most common Docker commands, which is docker image ls. That's saying, "Give me a list of all of the images "that I have downloaded to this computer." I think you'll find, if you run that command, there will be a long pause, it's trying to connect to your Docker server. Yeah, it was well over a minute for me before I got this error during connect. Can you see that it's clearly trying to connect to some kind of IP address somewhere? I think it's worth explaining what's going on here on a caption. What's happening here is that the Docker command line, this is where you were entering that docker command, is trying to connect to Docker itself, which, typically, you run as a separate daemon process. If you're not running on Linux, and I assume most of you probably aren't running on Linux, there's a problem here because, just as with Kubernetes, this Docker daemon needs to run on Linux because it's using various features of the Linux operating system to support containers. A little digression is that Microsoft are currently working really hard to build their own support for Docker containers built into Windows, but at the time of recording, that's a kind of experimental feature that isn't in common use. What will happen is, and this is a very similar story to what's been happening in Kubernetes, assuming you're not running on Linux, the setup is going to be, the Docker command line is actually going to look for a virtual machine, which, by default, is that Oracle VirtualBox that you saw earlier. It's going to look for a Docker daemon running in this virtual machine. What you can do with a Docker tooling that you've just installed is start up this virtual machine, and start up a new Docker daemon. That's absolutely fine, but because you're on a Kubernetes course, I have a plan. Of course, in the previous section, you went through all of that pain of installing Minikube, which is, as you know, a cut-down version of Kubernetes. What I haven't told you is that, inside Minikube is an installation of Docker. It has a Docker daemon running just fine. What we can do, and this is just a little bit of a trick that I often use, if we're already running Minikube, then we might as well tell the Docker command line to use Minikube's version of Docker to do our work. It's a neat little trick. Let's switch across to the terminal, and I'll show you how it works. I hope you managed to instal Minikube in the previous section. I don't know if it's running for you at the moment. If you're not currently running Minikube, then let's get it started with minikube start. If you're running on Windows 10 Professional, then you will need those extra command line arguments. Jet back to the previous section for details on that. As always, this takes quite a long time to start, so let's do a video edit here. Great, we should have Minikube up and running now. Now, remember, there is a Docker environment inside that Minikube. Now, at present, just to remind you, if we do a docker image ls, you're probably still going to see an error. That's because we need to configure Docker to tell it that we are talking to the Minikube environment rather than the traditional Docker that we run in its own virtual machine. Now, what we can do here is, we can use the command minikube followed by docker-env, and that's going to tell you what environment variables you need to set up in order for your Docker command line to talk to the Docker inside Minikube. If you're on Mac, if you're on Linux, or if you're on Windows using Cygwin, then you could copy and paste these export commands, or even better, you can just copy this eval here. All that's going to do is, it's going to run that minikube docker-env, and take this output, and then execute the output. It's going to run these four exports. Let's try that. I'll copy and paste. All that has done is, if I do a echo $DOCKER_HOST, for example, you can see that the value here is matching the value here. Just in case you're working in the standard Windows command prompt, which, to be honest, I don't recommend, you would be better on something like Cygwin, but if you have decided to use the standard Windows command shell, you might be worried that all of that Unix-y stuff that we've just seen won't work for you. Well, I've just switched my command prompt for a demonstration. I must admit, I've never tried this. I was surprised to see the results. You can see that they've actually thought of that, and if you are running on the command prompt, then it will issue standard DOS command prompts, I suppose they are. These will be set commands. You can see, there's a final REM statement here, which suggests that we can just copy this here, and if we run that, we'll get exactly the same results as we just did over in Cygwin. Just to remind you, don't mix and match. Don't use Windows command shell sometimes, and Cygwin some other times. Choose one or the other. Otherwise, things get in a terrible mess. I just wanted to do that to show you that, if you are on the Windows command prompt, you're not left out. We've now set up these environment variables, and the big thing now is, you should be able to type the command docker image ls, and what we're seeing here is a list of all of the Docker images that are contained inside the Minikube virtual machine. Now, these images are nothing to do with us. We never downloaded them. In fact, they're the Docker images that Minikube requires to set up a Kubernetes environment. We will be looking at some of these images a bit later on in the course, but for now, just think of them as internal images that Minikube needs. That's a little trick you can do. We're effectively reusing the Docker process inside Minikube. Now, the beauty of reusing the Docker process that's inside Minikube rather than starting up the Docker daemon again is just that it's more efficient on your computer's resources. I often work on a laptop, which isn't very powerful. There isn't a lot of RAM in there, and if I'm running Minikube and I'm running Docker Toolbox at the same time, then that's two virtual machines that my laptop has to manage, and it really does start to struggle. This is a nice trick that I use quite often.