Running the first container

Before we start, we want to make sure that Docker is installed correctly on your system and ready to accept your commands. Open a new Terminal window and type in the following command:

$ docker -v 

If everything works correctly, you should see the version of Docker installed on your laptop output in the Terminal. At the time of writing, it looks like this:

Docker version 17.12.0-ce-rc2, build f9cde63 

If this doesn't work, then something with your installation is not right. Please make sure that you have followed the instructions in the previous chapter on how to install Docker for Mac or Docker for Windows on your system.

So, you're ready to see some action. Please type the following command into your Terminal window and hit return:

$ docker container run alpine echo "Hello World" 

When you run the preceding command the first time, you should see an output in your Terminal window similar to this:

Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
2fdfe1cd78c2: Pull complete
Digest: sha256:ccba511b...
Status: Downloaded newer image for alpine:latest
Hello World

Now that was easy! Let's try to run the very same command again:

$ docker container run alpine echo "Hello World" 

The second, third, or nth time you run the preceding command, you should see only this output in your Terminal:

 Hello World  

Try to reason about why the first time you run a command you see a different output than all the subsequent times. But don't worry if you can't figure it out, we will explain the reasons in detail in the following sections of the chapter.