This post is about using docker-machine to create, use and manage a Docker host inside of a local virtual machine. From here.
First you need to install the latest version of Docker and VirtualBox. In my case they are “Docker 18.03.1-ce for Mac” and “VirtualBox 5.2.10 for Mac”.
Create a machine(VM)
1 | docker-machine create --driver virtualbox default |
Connect to the machine(VM)
First, update your local Docker environment variables to make your local Docker client connect to Docker inside the created machine rather than your local Docker.
1 | # 1. Show the content. |
This should be done every time when you open a new terminal in which you want to operate the Docker machine. Or you can set this into your “/.zshrc” or “/.bashrc” file, but if you do so, you have to make sure the Docker machine(VM) is running. More details of how to do so can be found in the official document here.
Operation
1 | # 1. Get the host IP address. |
Start and stop machines
1 | docker-machine stop default |
Use “unset” command to stop running Docker commands on the target machine
1 | unset DOCKER_TLS_VERIFY |
Besides the usage on local machine(VM), Docker Machine is also working with Docker host cloud providers. More details can be found here.