Install and setup

Welcome to Docker! This guide will take you through the various mini-tutorials to help you understand Docker.

Setup

The first step is to ensure that you install Docker on your machine. Since this tutorial was first written, Docker is now available for installation on a number of Linux distributions and also available for Windows and Mac operating systems.

Please visit https://docs.docker.com/engine/installation/#supported-platforms and select the Docker CE for installation on your platform. For the rest of the series, I shall be using Docker for Mac.

Once you have the setup done, I suggest that you test out your installation via the command given below:

Let’s try the hello-world example image. Give the following command at the prompt:

$ docker run hello-world

This should download the very small hello-world image and print a “Hello from Docker“ message.

Understand what we are running!

A lot of stuff happened behind the scenes to get the Hello World running. While we may not go into the specifics of all that for now, these are roughly the steps:

  1. You used the docker client application via the docker command.

  2. You gave the command run hello-world to the docker client application.

  3. In other words, you told the docker client to create an instance of a Docker Image titled hello-world.

  4. Where is this Docker Image? On your local system ? Somewhere on the Internet ? What is going on ?

  5. Well, the default behaviour is a sensible one i.e. the docker client looked for an Image titled hello-world in your local repository i.e. on your local machine. It did not find it (obviously) — so it went to the Internet and hit a URL at Docker Registry ( a public repository of Docker Images hosted by the company behind Docker). It found it there (I cheated … since I knew the name “hello-world” is one of the existing images out there. But you get the point). Once found, it started to download the Image (all its layers) and once it was present locally, it launched an instance (Container) based on that image.

  6. The default command was then executed to print out some message on the console, which is what you saw.

Try out the following Docker commands

Since the image “hello-world” is now present locally, it should be available in our local repository.

Try out :

$ docker images

and verify that you see the image listed there.

Try launching another container based on the same image. Give the following command:

$ docker run hello-world

It should print out the same message that you saw earlier.

The command $ docker ps gives you a list of running containers. Try it out and see if you can find any running.

Try out:

$ docker ps --all 

and see if they are visible now.

Use ‘ — help’ option. For e.g. docker ps — help

Even if you do not understand everything at this point in time, that is fine. These commands were meant to get you to start thinking of the typical operations you will need to understand/execute while dealing with Images / Containers.

Last updated