Join Arun Gupta for an in-depth discussion in this video Docker and Java, part of Docker for Java Developers.
- [Narrator] Alright, so you understood the basic concepts of Docker, but I'm a Java developer. How does it matter to me? And, what can I do with this? Well, as a Java developer, you are familiar with the concept of WORA, or Write Once, Run Anywhere. How does that work? Well, I mean, you have a Java source file. You take the Java source file. You give it to the Java compiler. The Java compiler then takes it, generates a .class file. Then, you have different tools like Maven, Gradle, so on, so forth. You take those class files and you pack them into a JAR or a WAR or an EAR file.
Okay, cool. So, you've taken the Java source file, compiled into class, and then packaged it into a JAR, WAR, or EAR. Now, on a variety of operating systems, whether it's Mac or Windows or Ubuntu or any flavor of Linux for that sake, there is a JVM, or Java Virtual Machine that is running. That JVM now understands the format of this class file, which is a Java bytecode. And, that's what gives you the power of Write your source code once, and the JVM will understand the underlying bytecode and it will run out of the box.
Now, Docker is very similar, but not exactly same. And, I'll highlight the differences in a second, but let's understand what the similarity is first. As we talked about, Docker has this capability of creating an image. Images where all of your application configuration data is put together. Now, you have created that image once on a variety of operating systems. Once again, OS X, Windows, a variety of Linux. You have this thing called as running as Docker engine, or a Docker host. Now, the Docker engine understands the image format.
You have given me the image format. Just like your JVM understands the class format, the Docker understands the image format. It takes that image format and runs the container for you. Now, Docker is essentially a native Linux technology. It's built on concepts like cgroups, namespaces, et cetera. Those inherently exist in Linux, so on OS X and Windows, you do have to run sort of a virtual machine which we'll talk about a little bit later in the chapter. But, the point is, once you have the image ready, you can easily run it on a variety of operating systems.
We'll talk a little bit later on how we create an image. So, as I said, PODA which is Package Once, Deploy Anywhere, is very similar to WORA, but it's not exactly similar because based upon what is the base operating system that you're using for an image, it could run only on that operating system. And, we'll talk about this differentiation and will understand this better when we go later in the chapter of creating an image essentially. So, just the way you do WORA in Java, the same concept is of PODA in Doc.
Well, out of the important difference that people need to understand is how is Docker really difference from virtual machines? A lot of people call Docker as a virtualization technology. I would like to be a myth-buster for that. It's not a virtualization technology. Docker is an application delivery technology. Well, let's try to understand what that means. On the left, what you see is a very classical virtual machine environment. So, you have your infrastructure on-premise, cloud, laptop, whatever it is. You have a host operating system running, which is whatever your base operating system is.
On a host operating system, you would run a hypervisor. Let's say, a type two hypervisor like Virtual Box or anything. Let's say my host operating system is Windows or Mac or Linux, and on top of that, I went on a different operating system. For example, let's say my host operating system is OS X and, on top of that, I want to run a Windows operating system. So for that, I would need to run a type two hypervisor and then, using Virtual Box, I can create a Windows VM on a Mac OS X.
Now, if I want to build an application around an application within Windows, then I would have to packet my application as a full-blown operating system sitting over there. It's literally delegating for networking and hard drives. Very basic needs are being filled by the underlying host operating system. So, on a given infrastructure, if you have multiple virtual machines running, there's a limit because each operating system has its own memory requirements, CPU requirements, et cetera. So, you are stalled by the capacity of the underlying operating system.
The density is very low. Look on the right-hand side now, which is, you have same underlying infrastructure. This is not a host operating system. It's just a simple operating system on which your Docker engine is running. Now, the Docker engine has a whole bunch of images. In that image, instead of a full-blown operating system, you have a minimal operating system. What does it mean by minimal operating system? As we discussed earlier, Docker relies upon basic Linux capabilities like cgroups and namespaces.
So, instead of having one gigabyte Ubuntu guest operating system on a typical virtual machine, I can use 120 megabytes Ubuntu base operating system on the Docker side and then packet my application in there. Everything else is provided by Docker engine. What that gives you? Well, first of all, that gives you a much smaller image, but because of the smaller image and lesser requirements, you can have much more densely packed. You can have agility of the application.
You can have the scalability of the application achieved much more easily. So, essentially, Docker which is an application delivered technology, is very different from a virtual machine technology. So, I think understanding the concept that how PODA matches with WORA, and how Docker is different from virtual machines, is fundamentally important. Once you understand that, then we can go forward and look a little bit more concepts of Docker.
Arun Gupta explains how to run containers and build images, as well as how to deploy multi-container applications on multiple hosts. Arun also covers Docker clustering, demonstrates how to run stateful containers, shares strategies on how to persist the state of stateful containers, and goes into monitoring Docker containers.
- Getting started with Docker
- Running your first Docker container
- Creating your first Docker image
- Copying files in a Docker image
- Running JAR files from a Docker image
- Working with Docker Compose
- Creating a multi-node swarm mode cluster using Docker Machine
- Deploying services to swarm mode
- Creating a multi-node swarm mode cluster on AWS
- Creating a database cluster using Docker Service
- Monitoring Docker with Prometheus
- Monitoring Docker with cAdvisor