Docker Tutorial

Jakob Jenkov
Last update: 2019-10-05

Docker is a simple way to package an application and server configuration as a Docker image, using a simple package specification called a Dockerfile. The Docker image can then be started in as many instances as you would like. Each running instance of a Docker image is called a Docker container This Docker tutorial explains what Docker images, containers and Dockerfile's are, how to create, run, and publish them and much more.

Docker Benefits

The big benefits of packaging an application along with its server configuration using a Dockerfile are:

  • You don't forget how your server was configured. The Dockerfile remembers that for you.
  • You can easily run your application on a new Docker host. Just deploy the Docker image for your application to that Docker host, and start it up. It's all automated.
  • Cluster tools like Kubernetes and Docker Swarm can easily manage Docker containers in clusters for you.
  • Many cloud platforms can deploy Docker containers easily. Docker is thus a simple way to become a bit more cloud independent.
  • Docker containers are an easy way for your clients to install your application on their own servers.

What is a Docker Container?

The Linux operating system has several features which allows for containerization of applications running on top of the operating system (OS). These containerization features provide the ability to separate the file system and networks of containerized applications. In other words, one containerized application cannot access the file system or network of another containerized application, unless you explicitly allow it. Docker uses these Linux containerization features and exposes them via an easy to use set of tools.

Containerized applications running on a Linux OS.

Docker Containers vs. Virtual Machines

Docker containers are similar in nature to virtual machines. However, a virtual machine has an extra OS in the total stack. A virtual machine has a VM OS, and then the VM is running on some computer which also has its own OS.

A Docker container, on the other hand, does not have its own internal OS. The container runs directly inside the host Linux OS. Thus, a Docker container is smaller in size, since it does not contain the whole VM OS. Docker containers can also perform better, as there is no virtualization of the VM necessary.

Docker containers vs. virtual machines - virtual machines have an extra VM OS.

Dockerfile

As mentioned earlier, you specify what to include in your Docker container via a special file which by convention is called Dockerfile. The Dockerfile contains a set of Docker instructions which are executed by the Docker command line tool. The result is a Docker image. The Dockerfile is explained in more detail in the Dockerfile Tutorial.

Docker Image

When the Docker command line tool executes the instructions inside a Dockerfile, the command line tool produces a Docker Image. A Docker Image is a portable, executable recipe for a Docker container. The Docker image contains all needed files and instructions to run the corresponding Docker container. It is possible to start multiple Docker containers from the same Docker image.

A Dockerfile can be used to generate a Docker image.

Docker Registry

Docker images can be stored in a Docker Registry. A Docker Registry is a Docker image repository where Docker images can be uploaded to, and also downloaded from. A Docker Registry can be either private, meaning just for you, your organization or whoever else you give access, or public, meaning anyone can access it - or at least download Docker images from it.

A public Docker registry is a great way to allow potential users of your software to download, install and run the software. Simply package your application as a Docker image, upload it to a public Docker Registry, and your users can access it.

The Docker company has hosted Docker Registries as a service. They have both public and private Docker Registries available. Some cloud provides like AWS, Azure and Google also have Docker Registries which you can use to upload your Docker images too, for easy deployment onto virtual machines or Kubernetes clusters on their cloud infrastructure.

A Docker image can be stored in, or downloaded from, a Docker registry.

Docker Command Line Tools

The Docker command line tools come with Docker when you install Docker on your computer. The Docker command line tools can build a Docker image from a Dockerfile, upload a Docker image to a remote Docker registry, download a Docker image from a remote Docker registry, and start and stop Docker containers from Docker images.

Docker Compose

The Docker Compose feature enables you to "link" multiple Docker containers into a single "composition", which can be installed / deployed and started up all at once. For instance, an application in one Docker container, and a database in another Docker container - in case both Docker containers are necessary for the application to run.

Jakob Jenkov

Featured Videos

Java ConcurrentMap + ConcurrentHashMap

Java Generics

Java ForkJoinPool

P2P Networks Introduction

















Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Previous
Next tutorial in this tutorial trail
Next