Estimated reading time: 15 minutes

Why use Docker

Docker allows for the rapid creation and management of self contained computer environments. These self contained environments, or containers, simplify software development, server management, and deployment. Docker allows system users to build configurations quickly and to run them on any Docker compatible system.

Key Docker concepts

Docker is a platform that helps develop, deploy, and run applications inside of Linux containers. Using Linux containers to deploy applications is called containerization. While containers are not new, their ease of use when deploying applications is.

Containers are increasingly popular because of their:

  • Lightness: Containers leverage and share host resources.
  • Flexibility: Even the most complex applications can be containerized.
  • Swap-ability: You can deploy updates and upgrades on-the-fly.
  • Portability: You can build locally, deploy to the cloud, and run containers anywhere.

Images and containers

An image is an executable package that includes everything needed to run an application: code, runtime libraries, environment variables, and configuration files. Images are built, then containers are launched by running images.

A container is a runtime instance of an image. It is what runs in memory when the image is executed. You can see a list of your running containers with the command docker ps

Containers and virtual machines

Containers run natively in Linux and share the valuable resources of the host machine with other containers. They run as discrete processes, making them lightweight, taking no more memory than other applications. On the other hand, virtual machines (VMs) run full-blown “guest” operating systems - each needing access to valuable host resources.

TODO Container stack example Virtual machine stack example (image)

First steps

1. Install Docker.

Docker can be installed on almost any desktop or laptop computer, as well as on most servers and specialty computers like the Rasberry Pi. It's best to install a copy of Docker locally. If you're working on a tablet, phone, or Chromebook instead follow the Docker in your own Cloud tutorial.

After finishing your istallation, add your user account to the docker group. Read more.

2. Test Docker version

  1. Run docker --version to ensure that you have a supported version of Docker:
docker --version

Docker version 17.12.0-ce, build c97c6d6

  1. Run docker info or (docker version without --) to view more details about your docker installation:
docker info

Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 17.12.0-ce
Storage Driver: overlay2
...

3. Test Docker installation

  1. Test that your installation works by running the simple Docker image - hello-world:
docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
...

  1. List the hello-world image that was downloaded to your machine:
docker image ls

  1. List the hello-world container (spawned by the image) which exits after displaying its message. If the container was still running, you would not need the --all option:
docker container ls --all

CONTAINER ID     IMAGE           COMMAND      CREATED            STATUS
54f4984ed6a8     hello-world     "/hello"     20 seconds ago     Exited (0) 19 seconds ago

Recap

## List Docker CLI commands
docker
docker container --help

## Display Docker version and info
docker --version
docker version
docker info

## Execute Docker image
docker run hello-world

## List Docker images
docker image ls

## List Docker containers (running, all, all in quiet mode)
docker container ls
docker container ls --all
docker container ls -aq

Conclusion of part one

Containerization makes development and deployment seamless. For example Docker containerized:

  • applications have no external system dependencies
  • updates can be pushed quickly to any part of a distributed application
  • resource density can be optimized

Using Docker scaling your application is a matter of spinning up new executables, not configuring and running heavy Virtual Machines.