Learn Docker:Fundamentals of Docker 19.x
上QQ阅读APP看书,第一时间看更新

Setting up Docker Toolbox

Follow these steps for setup:

  1. Let's use docker-machine to set up our environment. First, 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
  1. OK, we can see that there is a single VM called default installed, but it is currently in the STATE of stopped. Let's use docker-machine to start this VM so we can work with it:
$ docker-machine start default

This produces the following output:

Starting the default VM in Docker Toolbox

If we now list the VMs again, we should see this:

Listing the running VMs in Docker Toolbox

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

  1. 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

This will generate the following output:

Creating a new default VM in Docker Toolbox

If you carefully analyze the preceding output, you will see that docker-machine automatically downloaded the newest ISO file for the VM from Docker. It realized that my current version was outdated and replaced it with version v18.09.6.

  1. 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

This outputs the following:

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/gabriel/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)
  1. We can execute the command listed on the last line in the preceding code snippet to configure our Docker CLI to use Docker running on the default VM:
$ eval $(docker-machine env default)
  1. And now we can execute the first Docker command:
$ docker version

This should result in the following output:

 

Output of docker version

We have two parts here, the client and the server part. The client is the CLI running directly on your macOS or Windows laptop, while the server part is running on the default VM in VirtualBox.

  1. Now, let's try to run a container:
$ docker run hello-world

This will produce the following output:

The preceding output confirms that Docker Toolbox is working as expected and can run containers.

Docker Toolbox is a great addition even when you normally use Docker for Desktop for your development with Docker. Docker Toolbox allows you to create multiple Docker hosts (or VMs) in VirtualBox and connect them to a cluster, on top of which you can run Docker Swarm or Kubernetes.