Docker Toolbox

Docker Toolbox has been available for developers for a few years. It precedes the newer tools such as Docker for Mac and Docker for Windows. The toolbox allows a user to work very elegantly with containers on any Mac or Windows computer. Containers must run on a Linux host. Neither Windows or Mac can run containers natively. Thus, we need to run a Linux VM on our laptop, where we can then run our containers. Docker Toolbox installs VirtualBox on our laptop, which is used to run the Linux VMs we need.

As a Windows user, you might already be aware that there exists so-called Windows containers that run natively on Windows. And you are right. Recently, Microsoft has ported the Docker engine to Windows and it is now possible to run Windows containers directly on a Windows Server 2016 without the need for a VM. So, now we have two flavors of containers, Linux containers and Windows containers. The former only run on Linux host and the latter only run on a Windows Server. In this book, we are exclusively discussing Linux containers, but most of the things we learn also apply to Windows containers.

Let's use docker-machine to set up our environment. Firstly, we list all Docker-ready VMs we have currently defined on our system. If you have just installed Docker Toolbox, you should see the following output:

List of all Docker-ready VMs

The IP address used might be different in your case, but it will be definitely in the 192.168.0.0/24 range. We can also see that the VM has Docker version 18.04.0-ce installed.

If, for some reason, you don't have a default VM or you have accidentally deleted it, you can create it using the following command:

$ docker-machine create --driver virtualbox default

The output you should see looks as follows:

Creating the VM called default in VirtualBox

To see how to connect your Docker client to the Docker Engine running on this virtual machine, run the following command:

$ docker-machine env default

Once we have our VM called default ready, we can try to SSH into it:

$ docker-machine ssh default

When executing the preceding command, we are greeted by a boot2docker welcome message.

Type docker --version in the Command Prompt as follows:

docker@default:~$ docker --version
Docker version 17.12.1-ce, build 7390fc6

Now, let's try to run a container:

docker@default:~$ docker run hello-world

This will produce the following output:

Running the Docker Hello World container