© Kinnary Jangla 2018
Kinnary JanglaAccelerating Development Velocity Using Dockerhttps://doi.org/10.1007/978-1-4842-3936-0_4

4. Docker Basics

Kinnary Jangla1 
(1)
San Francisco, CA, USA
 

Essential foundations, starting points, and fundamentals

In this chapter, we will look into the Docker terminology that has been used in the previous chapters of this book and which I will continue to use in future chapters.

You’ll see the different components of the Docker architecture, including the Docker Engine, Docker Hub, Docker clients, Docker host, and Docker registries. You’ll see how different Docker objects are created by the Docker daemon and how Docker Hub can be used to pull existing Docker images and buy, sell, or distribute images for free.

Additionally, you will learn how to install Docker on the Mac operating system (OS) platform.

I will examine more closely some of the basic Docker commands, providing an example of the use of each command, so that you can play around with it and then follow it with your own example.

Terminology

Before you begin to approach the fundamentals of Docker, it is important to learn the associated lingo. Following are certain keywords and phrases that you will come across frequently, now that you’re on the path to becoming a Docker expert!
  • Image: A Docker image is a bundle of all the dependencies and configurations that an application depends on to run successfully. An image is this package that runs inside a container. Once an image is created, it cannot be changed. In other words, a Docker image is immutable.

  • Container: A Docker container is a lightweight instance of a Docker image. It is a running process that has been isolated using namespaces and uses the image for its root file system.

  • Dockerfile: A Dockerfile is a text file that contains instructions to build a Docker image.

  • Building a Dockerfile: This refers to building the instructions in the Dockerfile, in order to create a Docker image that can then run inside a Docker container.

  • Compose: This refers to a command-line tool that operates on one or more files that are a composition of multiple Dockerfiles of different applications/services, in a sense. With the Compose tool, you can run a single YAML file and get the images build to create and have them all running together.

Architecture

Before mastering Docker, let’s get into how it all works behind the scenes, to get a solid understanding of how it really works and how its different components interact with one another.

To begin with, let’s look at Docker’s different components:
  • Docker platform

  • Docker Engine

  • Docker architecture
    • Docker client

    • Docker daemon

    • Docker registries

  • Docker objects
    • Images

    • Containers

    • Services

  • Docker Hub

As you have seen in the previous chapters, some of the advantages of Docker are process- and application-level isolation, portability, and ease of deployment and testing. Many different components come into play to support these scenarios. So, let’s delve into the components one at a time.

Docker Platform

Docker provides a platform to bundle dependencies and other information, such as environment variables, configurations, settings, etc., into a single isolated environment. Owing to this isolation, dependencies across applications do not interfere with each other, and, hence, multiple applications can run inside their own containers. These containers can all run simultaneously on a single host machine. Because containers are different than virtual machines (VMs), in that they don’t need a hypervisor later and can run directly on the host machine’s kernel, a lot more containers can run on a single hardware machine than if you were to use VMs.

The Docker platform also provides the ability to manage your containers, allowing you to develop and test your applications using containers. When ready, you can also deploy your application in its production environment, using containers.

Docker Engine

The Docker Engine is a client-server application. It consists of the following three parts, as shown in Figure 4-1.
  1. 1.

    A server process, also known as a daemon process. This is a background process that is continuously running and constantly listening to the REST API interface for any commands to process.

     
  2. 2.

    A REST API interface that programs can talk to, in order to communicate with the Docker daemon. This can be accessed by an HTTP client.

     
  3. 3.

    A client that is a command-line interface (CLI).

     
../images/465114_1_En_4_Chapter/465114_1_En_4_Fig1_HTML.jpg
Figure 4-1

Docker Engine architecture

The way to get anything done using Docker is through the Docker client, via the CLI or a script composed of commands. The client then communicates these commands, via the REST API, to the Docker daemon, which is the server. The Docker daemon then gets the job done. It creates such Docker objects as images, containers, volumes, etc.

Let’s look more extensively into Docker’s client-server architecture.

Docker Architecture

The Docker system mainly consists of the Docker client, daemon, and registry (Figure 4-2).
../images/465114_1_En_4_Chapter/465114_1_En_4_Fig2_HTML.jpg
Figure 4-2

Docker client-server architecture

Docker Client

The Docker Client is the primary way in which most users interact with Docker. When you run commands using the CLI, these commands are then sent to the Docker daemon, using the Docker API interface. The Docker daemon or the dockerd then executes these commands and creates relevant Docker objects. The Docker client has the ability to communicate with multiple Docker daemons.

Docker Daemon

The Docker daemon is a server process that is persistent in nature and runs in the background. It continuously listens to the REST API interface and looks for any incoming requests to process commands. The daemon can listen to the API interface using different socket types, such as Unix, TCP (transmission control protocol), and FD (file descriptor) .

Docker Registries

The images created by the Docker daemon must be stored at a certain location, for ease of access. The Docker registry is this location. There are public registries, such as the Docker Hub, that can be used by anyone. By default, Docker looks for images on the Docker Hub, but this can be configured to use your private registry as well.

Commands such as Docker pull retrieve the required images from your configured registry and Docker push pushes the image to this same configured registry.

From a Docker store, you can buy, sell, or distribute images for free. You can then use these images to deploy an application in your test or production environment.

Let’s move forward a bit and look at the different objects of Docker that have been referenced multiple times in this book so far.

Docker Objects

With the use of Docker, different objects are generated, mostly by the Docker daemon. Some of these objects are images, containers, services, and storage.

Images

A Docker image is a read-only file system that contains instructions to create a container that can run an application. Most of the time, a Docker image is based on another image and is customized. You could either use existing images published in public registries, such as the Docker Hub, or create your own image.

A Dockerfile is used to build a Docker image. A Dockerfile contains simple instructions that can be understood by the Docker daemon, to create the image and run it.

Docker images are layers that correspond to each instruction in the Dockerfile. A part of what makes a Docker image super lightweight is that when you modify a part of the Dockerfile, only that layer is modified, rather than the entire image.

Containers

A Docker container is an instance of an image. An image runs inside a container. You can manage a container using stop, start, and delete commands. Multiple containers can be connected to one another through a network. They can be connected to storage, and they can also talk to one another.

As you have seen in Chapter 1, containers are much more lightweight than VMs, owing to their startup times being very fast.

In order to create a container, an image, in addition to the container’s configuration and settings, is provided. When a container is deleted, everything related to the container is also deleted, including state and storage.

The Docker run command is used to run a container. When you run this command, the following things happen:
  1. 1.

    The Docker image is pulled from the configured registry.

     
  2. 2.

    A new Docker container is created.

     
  3. 3.

    A local file system is allocated to that container, to enable creation and modification of files and directories in its local file system.

     
  4. 4.

    The container is connected to the default network, unless you configure a networking option. A container is assigned an IP address.

     
  5. 5.

    Docker starts running the container and attaches it to your local terminal. This allows you to interact with this container.

     
  6. 6.

    You can stop or remove the container, using your terminal input, at any time.

     

Services

In a distributed application, different functionalities of the app constitute different services. For example, if you are building an application for suggestions based on keywords entered by the user, you might want a front-end service that takes the word and sends it to the service that verifies the legitimacy of the word. This might, in turn, go to another service that might execute an algorithm, in order to generate the suggestions, etc., which are then returned to the service.

These are all different services on different Docker containers that sit behind different Docker daemons. These Docker daemons are all connected through the network and interact with each other. To the user, this might look like a single application that runs, but behind the scenes, these are multiple services that make the entire application function.

All these services work together as a swarm, managed by different managers and workers. Each swarm contains a Docker daemon. These daemons communicate with each other using the Docker API.

A Docker Compose YAML file is used to get all these services up and running together. Later, in Chapter 6, you will see how to use the Docker Compose tool in detail.

Docker Hub

Docker Hub is the primary location for storage of Docker images. It is a cloud-based public registry from which you can pull images or push images to. It also links to Docker Cloud. It is a centralized store for image discovery and distribution. By default, Docker is configured to use this public registry.

A user can buy or sell Docker images from the Docker Hub. Alternatively, a user can also distribute Docker images for free on the hub. A user can search for Docker images using the Docker Hub user interface or the CLI.
kinnaryjangla@dev-abc: docker search alpine
NAME                                   DESCRIPTION                                         STARS    OFFICIAL    AUTOMATED
alpine                                 A minimal Docker image based on Alpine Linux...     4203     [OK]
mhart/alpine-node                      Minimal Node.js built on Alpine Linux               379
anapsix/alpine-java                    Oracle Java 8 (and 7) with GLIBC 2.28 over A...     346                  [OK]
gliderlabs/alpine                      Image based on Alpine Linux will help you wi...     177
frolvlad/alpine-glibc                  Alpine Docker image with glibc (~12MB)              162                  [OK]
alpine/git                             A  simple git container running in alpine li...     46                   [OK]
kiasaki/alpine-postgres                PostgreSQL docker image based on Alpine Linux       42                   [OK]
zzrot/alpine-caddy                     Caddy Server Docker Container running on Alp...     32                   [OK]
easypi/alpine-arm                      AlpineLinux for RaspberryPi                         30
davidcaste/alpine-tomcat               Apache Tomcat 7/8 using Oracle Java 7/8 with...     30                   [OK]
byrnedo/alpine-curl                    Alpine linux with curl installed and set as ...     17                   [OK]
etopian/alpine-php-wordpress           Alpine WordPress Nginx PHP-FPM WP-CLI               15                   [OK]
hermsi/alpine-sshd                     Dockerize your OpenSSH-server upon a lightwe...     12                   [OK]
davidcaste/alpine-java-unlimited-jce   Oracle Java 8 (and 7) with GLIBC 2.21 over A...     11                   [OK]
hermsi/alpine-fpm-php                  Dockerize your FPM PHP 7.2 upon a lightweigh...     10                   [OK]
alpine/socat                           Run socat command in alpine container               10                   [OK]
graze/php-alpine                       Smallish php7 alpine image with some common ...     9                    [OK]
yobasystems/alpine-xen-orchestra       Xen Orchestra running on Alpine Linux [docke...     8                    [OK]
masterroshi/xmrig-alpine               Cryptonote CPU Miner wrapped in a Alpine Doc...     8
spotify/alpine                         Alpine image with `bash` and `curl`.                5                    [OK]
tenstartups/alpine                     Alpine linux base docker image with useful p...     5                    [OK]
functions/alpine                       Alpine Linux / BusyBox with the OpenFaaS wat...     4
govuk/gemstash-alpine                  Gemstash server running on Alpine                   3                    [OK]
casept/alpine-amd64                    A basic alpine linux image.                         0
smartentry/alpine                      alpine with smartentry                              0                    [OK]

Now that we have looked behind the scenes at how Docker actually operates, let’s see how to install it.

Installing Docker

There are two Docker editions available to install.
  • Docker Community Edition (CE) : This works for small communities or individual developers looking to get started and experiment with Docker.

  • Docker Enterprise Edition (EE) : This is meant for enterprises that use Docker to ship business-critical applications that need to scale.

For the purposes of this book, let’s look at how to install the Docker CE.

Docker CE is available for both the Mac and Windows OSs. It is also available to Amazon Web Services and Microsoft Azure.

Let’s look at how to install Docker CE on the Mac OS platform. There are some system requirements to meet before you can install Docker on your machine. You will need a Mac machine model that is at least from 2010 or later. In addition, you will need at least 4GB of RAM.
  1. 1.
    Go to the Docker store at https://store.docker.com/editions/community/docker-ce-desktop-mac and click Get Docker, from the right-side pane, as seen in Figure 4-3.
    ../images/465114_1_En_4_Chapter/465114_1_En_4_Fig3_HTML.jpg
    Figure 4-3

    Getting the Docker Community Edition for Mac

     
  2. 2.
    Once you have the dmg file on your machine, double-click it and drag Moby the whale to the Applications folder, as shown in Figure 4-4.
    ../images/465114_1_En_4_Chapter/465114_1_En_4_Fig4_HTML.jpg
    Figure 4-4

    Drag Moby to your Applications folder

     
  3. 3.

    In the Applications folder, double-click the Docker app, as seen in Figure 4-5.

     
../images/465114_1_En_4_Chapter/465114_1_En_4_Fig5_HTML.jpg
Figure 4-5

Docker icon as seen in the Applications folder

Authorize Docker.app with your system password, after you launch it. You will need admin access to launch the different Docker components.
  1. 4.
    The Moby whale on the status bar on the top, as shown in Figure 4-6, indicates that Docker is now running.
    ../images/465114_1_En_4_Chapter/465114_1_En_4_Fig6_HTML.jpg
    Figure 4-6

    Docker icon on the status bar

     
  2. 5.

    If you have successfully installed the app, you will also see a pop-up with a success message, next steps, and tips, as shown in Figure 4-7.

     
../images/465114_1_En_4_Chapter/465114_1_En_4_Fig7_HTML.jpg
Figure 4-7

Successful installation of Docker shows a pop-up with next steps

To dismiss this pop-up, click the whale on the top status bar.

  1. 6.
    Right-clicking the whale on the status bar will give you options to set or modify your preferences, as shown in Figure 4-8.
    ../images/465114_1_En_4_Chapter/465114_1_En_4_Fig8_HTML.jpg
    Figure 4-8

    Right-click Docker menu on the status bar icon

     
  1. 7.

    Check About Docker, to ensure you have the latest version.

     

Now that we have Docker installed and running on our machines, let’s take a look at some basic Docker commands, so that you can play around and experiment with them.

Basic Docker Commands

Following are some basic Docker commands that you can start playing with.

docker container run

This runs a command in a new container. When a user runs the Docker run command, it isolates the containers in its environment and the configuration within its own local file system.

The Docker run command specifies an image, in order to run that image inside a container.

The basic docker container run command looks like this:
docker container run  [OPTIONS]  IMAGE  [COMMAND]  [ARG...]
Image is the existing image you want to run inside the container. With docker container run [OPTIONS], the developer can modify the defaults of the images. Some options types are
  • -d: You can choose to let the container run in the background, in detached mode, or in the foreground. By default, when -d is not specified, the container runs in the foreground.

  • -a: The foreground mode lets you attach your local console to the process’s (running inside the container) standard input output.

docker container create

The docker container create command lets you create a new container from an existing image that has been built previously. This is shown following. The –t command stands for “tty,” which sets a pseudo time of the container to live, and the -I command stands for “interactive” and keeps the standard input open, even if it’s not attached.

Usage:
docker container create  [OPTIONS]  IMAGE [COMMAND]  [ARG...]
Example:
kinnaryjangla@dev-abc:~/code/test$ docker container create –t -i myApp bash
38001kjhasd7qhs8whs7sh38729wajsh352191j888dhasg2
kinnaryjangla@dev-abc:~/code/test$

docker container start

The docker container start command lets you start a new container or a container that has been previously stopped, as shown here. The –t flag stands for “tty” and is used to give the container a pseudo time to live. The -I flag keeps the standard input open, even when it’s not attached.

Usage:
docker container start [OPTIONS] CONTAINER [CONTAINER...]
Example:
kinnaryjangla@dev-abc:~/code/test$ docker container create –t -i myApp bash 38001kjhasd7qhs8whs7sh38729wajsh352191j888dhasg20
kinnaryjangla@dev-abc:~/code/test$ docker start –a -i 38001kjhasd
root@38001kjhasd:/mnt/myApp #

docker container stop

The docker container stop command lets you stop a currently running container.

Usage:
docker container stop [OPTIONS] CONTAINER [CONTAINER...]
Example:
kinnaryjangla@dev-abc:~/code/test$ docker container stop 38001kjhasd

docker image build

The docker image build command builds the docker image using the instructions in the Dockerfile.

Usage:
docker image build [OPTIONS] PATH | URL | -
Example:
kinnaryjangla@dev-abc:~/code/test$ docker image build myApp/.
Sending build context to Docker daemon  1.649MB
Step 1/6 : FROM openjdk:8
 ---> ef09cb43251e
Step 2/6 : ENV CONFIG_FILE config/myApp.dev.properties HEAP_SIZE 4G LOG4J_CONFIG_FILE config/log4j.dev.properties NEW_SIZE 2G JAVA_COMMAND java
 ---> Using cache
 ---> 09c7e98f7c49
Step 3/6 : WORKDIR /opt/myApp
 ---> Using cache
 ---> 3c29b8fa2f25
Step 4/6 : ARG ARTIFACT_PATH=target/myApp-0.1-SNAPSHOT-bin.tar.gz
 ---> Using cache
 ---> c563d2e7990c
Step 5/6 : ADD $ARTIFACT_PATH /opt/myApp/
Successfully built bd6110589d1b

docker image pull

The docker image pull command pulls an image from a docker registry.

Usage:

docker image pull [OPTIONS] NAME[:TAG|@DIGEST]

Example:
kinnaryjangla@dev-abc:~/code/test$ docker image pull alpine
Using default tag: latest
latest: Pulling from library/alpine
8e3ba11ec2a2: Pull complete
Digest: sha256:7043076348bf5040220df6ad703798fd8593a0918d06d3ce30c6c93be117e430
Status: Downloaded newer image for alpine:latest
kinnaryjangla@dev-abc:~/code/test$

docker search

You can search for Docker images using the docker search command.

Usage:
docker search  [OPTIONS]  TERM
Example:
kinnaryjangla@dev-abc:~/code/test$ docker search alpine
NAME                                   DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
alpine                                 A minimal Docker image based on Alpine Lin...   4203      [OK]
mhart/alpine-node                      Minimal Node.js built on Alpine Linux           379
anapsix/alpine-java                    Oracle Java 8 (and 7) with GLIBC 2.28 over...   346                  [OK]
gliderlabs/alpine                      Image based on Alpine Linux will help you ...   177
frolvlad/alpine-glibc                  Alpine Docker image with glibc (~12MB)          162                  [OK]
alpine/git                             A  simple git container running in alpine ...   46                   [OK]
kiasaki/alpine-postgres                PostgreSQL docker image based on Alpine Linux   42                   [OK]
zzrot/alpine-caddy                     Caddy Server Docker Container running on A...   32                   [OK]
easypi/alpine-arm                      AlpineLinux for RaspberryPi                     30
davidcaste/alpine-tomcat               Apache Tomcat 7/8 using Oracle Java 7/8 wi...   30                   [OK]
byrnedo/alpine-curl                    Alpine linux with curl installed and set a...   17                   [OK]
etopian/alpine-php-wordpress           Alpine WordPress Nginx PHP-FPM WP-CLI           15                   [OK]
hermsi/alpine-sshd                     Dockerize your OpenSSH-server upon a light...   12                   [OK]
davidcaste/alpine-java-unlimited-jce   Oracle Java 8 (and 7) with GLIBC 2.21 over...   11                   [OK]
hermsi/alpine-fpm-php                  Dockerize your FPM PHP 7.2 upon a lightwei...   10                   [OK]
alpine/socat                           Run socat command in alpine container           10                   [OK]
graze/php-alpine                       Smallish php7 alpine image with some commo...   9                    [OK]
yobasystems/alpine-xen-orchestra       Xen Orchestra running on Alpine Linux [doc...   8                    [OK]
masterroshi/xmrig-alpine               Cryptonote CPU Miner wrapped in a Alpine D...   8
spotify/alpine                         Alpine image with `bash` and `curl`.            5                    [OK]
tenstartups/alpine                     Alpine linux base docker image with useful...   5                    [OK]
functions/alpine                       Alpine Linux / BusyBox with the OpenFaaS w...   4
govuk/gemstash-alpine                  Gemstash server running on Alpine               3                    [OK]
casept/alpine-amd64                    A basic alpine linux image.                     0
smartentry/alpine                      alpine with smartentry                          0                    [OK]

docker image ls

The docker image ls command is used to list all the Docker images on the host machine.

Usage:
docker image ls  [OPTIONS]  [REPOSITORY[:TAG]]
Example:
kinnaryjangla@dev-abc:~/code/test$ docker image ls
REPOSITORY    TAG          IMAGE ID      CREATED         SIZE
ubuntu        latest       cd6d8154f1e1   3 days ago     84.1MB
openjdk       7            bd6110589d1b   4 days ago     472MB
alpine        latest       11cd0b38bc3c   2 months ago   4.41MB

docker container ps

The docker container ps command is used to list all containers running on the host.

Usage:
docker container ps  [OPTIONS]
Example:
kinnaryjangla@dev-abc:~/code/test$ docker container ps
CONTAINER ID    IMAGE    COMMAND                 CREATED
e55ce4b2e4f5    alpine   "./bin/docker_run_..."  6 days ago
119b4b5eed95    ubuntu   "./bin/docker_run_..."  6 days ago

docker container rm

The docker container rm command is used to remove one or more containers. You cannot remove a running container without the –f flag to force it, which first stops the container and then removes it. In order to do that, you must first stop the container, using docker container stop <container-id>. This command execution is shown following:

Usage:

docker container rm [OPTIONS] CONTAINER [CONTAINER...]

Example:
kinnaryjangla@dev-abc:~/code/test$ docker container stop e55ce4b2e4f5
kinnaryjangla@dev-abc:~/code/test$ docker image rm 119b4b5eed95

docker container inspect

This command allows you to inspect the details of a container.

Usage:
docker container inspect [OPTIONS] CONTAINER [CONTAINER...]
Example:
kinnaryjangla@dev-abc:~/code/test$ docker container inspect f9d4b5c9aa49
[
    {
        "Id": "f9d4b5c9aa49fb22b23ae0d377236e1da80ceebc14c67550e36f6c0345eb2062",
        "Created": "2018-08-03T06:11:54.181815872Z",
        "Path": "/test/bin/entry_point.sh",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 30163,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2018-08-03T06:11:58.414063235Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:b657c637b59170b7ea275d0af93fed7b89b1c286aeacd5438052955911a89d7a",
        "ResolvConfPath": "/var/lib/docker/containers/f9d4b5c9aa49fb22b23ae0d377236e1da80ceebc14c67550e36f6c0345eb2062/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/f9d4b5c9aa49fb22b23ae0d377236e1da80ceebc14c67550e36f6c0345eb2062/hostname",
        "HostsPath": "/var/lib/docker/containers/f9d4b5c9aa49fb22b23ae0d377236e1da80ceebc14c67550e36f6c0345eb2062/hosts",
        "LogPath": "/var/lib/docker/containers/f9d4b5c9aa49fb22b23ae0d377236e1da80ceebc14c67550e36f6c0345eb2062/f9d4b5c9aa49fb22b23ae0d377236e1da80ceebc14c67550e36f6c0345eb2062-json.log",
        "Name": "/webapp_selenium-chrome_1",
        "RestartCount": 0,
        "Driver": "overlay",
        "MountLabel": "",

These are some basic commands you can start to explore. Let’s go through a little end-to-end Hello World example.

In the following example, we’ll pull an existing Hello World image, run it, and view the images and containers.
  1. 1.
    First, pull the hello-world Docker image. This will pull the image from the Docker Hub registry.
    kinnaryjangla@dev-abc:~/code/test$ docker image pull hello-world
    Using default tag: latest
    Latest: Pulling from library/hello-world
    9bbdshfg673e39ja: Pull complete
    Digest: sha256: fkjdh7t6dauadubiadadia8dya98777da9fiudfhd9a86fidfbdfid8fydisch
    Status: Downloaded newer image for hello-world:latest
     
  2. 2.
    Use docker images to view the image that was just pulled, as shown following.
    kinnaryjangla@dev-abc:~/code/test$ docker image ls
    REPOSITORY    TAG      IMAGE ID      CREATED    SIZE
    Hello-world   latest   ekjad89sjdfd 2 months ago
    1.85kB
     
  3. 3.
    Now run the hello-world image, which will run this image inside a new container, as follows.
    kinnaryjangla@dev-abc:~/code/test$ docker container run hello-world
    latest: Pulling from library/hello-world
    d1725b59e92d: Pull complete
    Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
    Status: Downloaded newer image for hello-world:latest
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
        (amd64)
     3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash
    Share images, automate workflows, and more with a free Docker ID:
     https://hub.docker.com/
    For more examples and ideas, visit:
     https://docs.docker.com/get-started/
     

This preceding example lets you go through an end-to-end scenario of pulling an existing Docker image, viewing the image, and running the image.

In the next chapter, we’ll take a closer look at how to create Docker images using Dockerfiles and run these images inside Docker containers.

Summary

In this chapter, we looked in detail at the Docker terminology that has been commonly used in the previous chapters of this book and that will continue to be used in future chapters.

We also examined the different components of the Docker architecture, including the Docker Engine, Docker Hub, Docker clients, Docker hosts, and Docker registries. We also saw how different Docker objects are created by the Docker daemon. We saw how Docker Hub can be used to pull existing Docker images and buy, sell, or distribute images for free.

Additionally, you saw how to install Docker on the Mac OS platform in detail.

We looked at some basic Docker commands, with sample usage and examples of each command, so that you can explore them further. We then walked through a simple end-to-end example of pulling the existing Hello World image and running it.

In the next chapter, I’ll go more into detail on how to build an image from a Dockerfile and run it inside a container.