What is Docker?

by Jun 29, 2016




Transcript – What is Docker?

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.

What is Docker?

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.

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.

Docker layers changes to create new containers. Each change is a new Docker container.

Docker layers changes to create new containers. Each change is a new Docker container.

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.

What is a Dockerfile?

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.

FROM java:8
MAINTAINER DJ Spiess ([email protected])
ADD /opt/dockerapp-1.0-SNAPSHOT.jar /opt/
ENTRYPOINT ["java", "-jar", "/opt/dockerapp-1.0-SNAPSHOT.jar"]

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.

Where can I get more Dockerfiles?

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.

How to write a Dockerfile

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.

We wrote a Dockerfile, built the container, and then ran the container.

We wrote a Dockerfile, built the container, and then ran the container.

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.

Conclusion

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!

<p><script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- DeegeU - Right Side -->
<ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-5305511207032009" data-ad-slot="5596823779"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>

Tools Used

  • Docker
  • Command Line

Media Credits

All media created and owned by DJ Spiess unless listed below.

  • No infringement intended

Intractable by Kevin MacLeod is licensed under a Creative Commons Attribution license (https://creativecommons.org/licenses/by/4.0/)
Source: http://incompetech.com/music/royalty-free/index.html?isrc=USUAN1100194
Artist: http://incompetech.com/

Crushin by Audionautix is licensed under a Creative Commons Attribution license (https://creativecommons.org/licenses/by/4.0/)
Artist: http://audionautix.com/

Get the code

The source code for “What is Docker” can be found on Github. If you have Git installed on your system, you can clone the repository by issuing the following command:

 git clone https://github.com/deege/what-is-docker.git

Go to the Support > Getting the Code page for more help.

If you find any errors in the code, feel free to let me know or issue a pull request in Git.

<h2>Don't miss another video!</h2> <p>New videos come out every week. Make sure you subscribe!<br><script src="//apis.google.com/js/platform.js"></script></p> <div class="g-ytsubscribe" data-channel="deegeu" data-layout="full" data-count="default"></div> <p></p>

Comments

comments

DJ Spiess

DJ Spiess

Your personal instructor

My name is DJ Spiess and I'm a developer with a Masters degree in Computer Science working in Colorado, USA. I primarily work with Java server applications. I started programming as a kid in the 1980s, and I've programmed professionally since 1996. My main focus are REST APIs, large-scale data, and mobile development. The last six years I've worked on large National Science Foundation projects. You can read more about my development experience on my LinkedIn account.

Pin It on Pinterest

Share This