In this video we're going to look at what is Docker, what does Docker do for us, and
how can we get started working with Docker for our applications.
Hi, I recently created a tutorial on deploying Java applications to Docker containers.
Many of you have asked that I create a series on Docker as well, so this video is the start
of that series.
You've likely heard about Docker.
It's one of the big buzzwords currently running through the IT industry.
Docker is a Linux container technology that lets us package and ship our applications
and everything it needs to execute into a standard format, and run them on all our existing
Linux hardware.
That might sound like a virtual machine, and it's a good start on how to think about Docker
containers.
Docker containers are similar to virtual machines in that our application runs on what seems
to be it's own hardware instance.
Every Docker container has it's own virtualized filesystem, memory, storage, CPU cycles and
so on.
Docker handles the port mappings for each container.
That mean we can have several applications answering to port 80, all on the same machine.
Every container is completely isolated from the other containers.
Just like a virtual machine.
Where Docker containers differ is they virtualize the operating system kernel, not the hardware.
That means we can't run any operating system, we have to run Linux.
However, we also don't need to install an operating system for every application we
want to run.
This makes our containers very lean.
It does this though a “layered” filesystem.
Docker starts with a Linux kernel that all containers use.
Then it layers the differences top of the kernel.
For example the libraries for each distro are layered on top of the Linux kernel.
Then apps can be layered on top of the distros.
Even a command like echo “Hello World” can make a container.Compare that to a virtual
machine that often requires 100s of megabytes, to even gigabytes.
Using a Docker container means we can run many more containers than virtual machines.
It also means we can set up larger environments on a single developer machine.
The next thing we’d want to know is how do we build a Docker container.
How do we specify what applications are run in our container?
A Docker container is described in a text file called a Dockerfile.
Every Dockerfile has a unique name, usually the username, an identifier, and optionally
a version identifier.
The Dockerfile describes everything different in our container we need to run our application.
The power of these files is they are like stackable bricks.
We begin by saying what we're starting with, and then we describe only what's different.
For example, if we wanted to run a Java application, our Dockerfile might look like this.
It says to start with the Java8 Dockerfile, where to add our Java application, and specify
how to run it.
The Java:8 Dockerfile is another Dockerfile that builds Java onto a common configuration
of Linux.
And that is built using another Dockerfile that installs Debian.
The beauty is if we wanted to create another Dockerfile for running say Node, we can start
with the same configured Linux Java uses.
In these files we're saying give us everything up to this point, and we'll tell you what's
different about our application.
We can also run other commands like packages to install, environment variables to set,
ports to expose, and so on.
But everything unique about our Docker container is specified in the Dockerfile.
Since this is a unique text file, we can give it to someone else and they can run exactly
what we're running, with the exact same environment.
We don't have to worry about anything getting missed, or another machine is configured differently.
All the configuration is contained inside the container.
This can easily scale to run hundreds or thousands of instances of our container.
It also means we can eliminate the "it runs on my machine excuse".
Packaging applications in Docker containers means the application should function the
same locally as it will deployed in another environment.
If we have a really cool Dockerfile, we can share it on Docker hub.
That's a repository of thousands of other Dockerfiles.
These describe containers to run applications like Node, MySQL, Wildfly, or any other application
we can think of.
In fact, many of these Dockerfiles are official releases from the companies that create these
tools.
So if we want a Wildfly Docker container, we should start with the official Wildfly
Dockerfile from Red Hat.
Docker hub is just one repository.
We can use our own, and even have private repositories.
The best way to get started with Docker is to download and install the Docker Toolbox.
The instructions for installing Docker Toolbox are very simple, so just pick your machine
and install.
This includes several tools, but the main tool is Docker Engine.
Docker Engine is the workhorse for creating and running Docker containers.
It's command line, but the commands are familiar if you know Linux.
The steps for creating and using a Docker container are, write the Dockerfile, build
the Docker container, and then run the Docker container.
Let's try it out.
We'll start by creating a simple Dockerfile that looks like this.
We'll base our container on Ubuntu.
We'll add one command that just echoes "Hello World".
Next we'll build the Dockerfile using this command in a command prompt.
(docker build .) We'll run this command from the directory where our Dockerfile resides.
When the container is built, Docker will say it successfully built the container, and it
will call it a series of hex digits.
So we'll tell Docker to run the container using the command (docker run 9662b397a0fd).
The hex digits will be different on your machine.
And it should print "Hello World”.
We could give the container a better name, and well cover the Dockerfile in depth in
the next video.
Since it's a very small container, lets talk about what we just did.
We created a file that described a Docker container.
Inside the container, we asked Docker to add Ubuntu and then run the echo command.
It runs the command, which prints "Hello World", and since it has nothing else to do the container
terminates.
What we didn't see, but we'll cover soon is that this was all run in a Linux container.
Complete with it's own filesystem, memory and so on.
The real power in Docker containers is we can run any application, not just echo or
any other Linux script commands.
We're going to cover Docker in depth in upcoming videos.
This is was just to explain what is Docker, and how we use it.
If you have any questions, add them to the comments below.
If there are specific Docker topics you want covered, let me know!
And if you enjoyed the video, please share the video with others.
You'll also want to sign up for the DeegeU newsletter.
That's a monthly email containing the month's videos, plus tips and news not in the videos.
And with that, I’ll see you in the next video!