Docker Machine
Containerization has become the foundation of modern software delivery, and Docker Engine remains one of the most widely used runtimes in this ecosystem. However, manually setting up Docker on local virtual machines, remote servers, or public cloud instances often involves repetitive SSH sessions, certificate handling, and network configuration. Docker Machine is the official command-line tool from Docker designed to automate the provisioning and management of Docker hosts across diverse infrastructure through a unified interface.
Its core value lies in abstracting away underlying differences. Whether the target is a laptop running VirtualBox, a bare-metal server in a data center, or a cloud instance on AWS or DigitalOcean, Docker Machine can use the appropriate driver to create the host, install the Docker Engine, and configure the TLS-secured connection between the local client and the remote daemon.
Although Docker Desktop and Kubernetes have since taken over certain use cases, Docker Machine remains highly practical for lightweight multi-environment testing, edge node management, and learning the mechanics of Docker remote daemon communication.
Core Concepts
Before diving into hands-on commands, it helps to understand the foundational concepts behind Docker Machine:
- Driver: The driver is the bridge that lets Docker Machine interact with different virtualization platforms or cloud providers. Common options include
virtualbox,vmwarefusion,hyperv,amazonec2, anddigitalocean. - Docker Host: A virtual machine or cloud instance provisioned by Docker Machine, pre-installed with Docker Engine and configured for remote API access.
- TLS Authentication: Docker Machine automatically generates certificates and keys to ensure encrypted and authenticated communication between the local Docker CLI and the remote Docker daemon.
- Environment Variables: The output of
docker-machine envcontains variables that route subsequentdockercommands from your local terminal to a specified remote host, eliminating the need to manually specify the host address for every operation.
Installation
Installing Docker Machine typically requires downloading the binary that matches your operating system and placing it in your system path. The following examples apply to Linux and macOS:
base=https://github.com/docker/machine/releases/download/v0.16.0
curl -L $base/docker-machine-$(uname -s)-$(uname -m) > /tmp/docker-machine
Next, make the binary executable and move it to a standard directory:
chmod +x /tmp/docker-machine
sudo mv /tmp/docker-machine /usr/local/bin/docker-machine
Verify the installation:
docker-machine version
If the terminal prints a version number, the tool is ready to use for creating and managing Docker hosts.
Creating and Managing Docker Hosts
Docker Machine provisions a new host on the target platform using the create command, automatically handling Docker Engine installation and TLS setup. For example, to create a local Docker host named dev-node using VirtualBox:
docker-machine create --driver virtualbox dev-node
After creation, use ls to list all managed hosts and their current status:
docker-machine ls
The output usually includes the host name, driver type, activation status, IP address, and Swarm-related information, giving you a quick overview of your infrastructure.
To make your local Docker CLI operate against a remote host, load that host's environment variables:
docker-machine env dev-node
Following the terminal prompt, run in Bash:
eval $(docker-machine env dev-node)
From this point on, commands such as docker run, docker ps, and docker build target the Docker daemon on dev-node rather than your local machine. To return to the local Docker environment, unset the variables:
eval $(docker-machine env -u)
Common Operational Commands
Once a host is provisioned, day-to-day maintenance relies on the following commands:
- Start a host:
docker-machine start <name> - Stop a host:
docker-machine stop <name> - Restart a host:
docker-machine restart <name> - SSH into the host:
docker-machine ssh <name>, useful for troubleshooting or manual configuration inside the virtual machine. - Inspect host details:
docker-machine inspect <name>, which returns JSON-formatted configuration including driver options, Swarm host address, and certificate paths. - Remove a host:
docker-machine rm <name>, which deletes the associated virtual machine or cloud instance; use with caution.
Together, these commands form a complete operational loop for managing single-node or small multi-node Docker environments.
Cloud Integration and Driver Flexibility
Beyond local virtualization, Docker Machine works