Docker-machine

Docker Machine is a tool that lets you install Docker Engine on virtual hosts, and manage the hosts with docker-machine commands. You can use Machine to create Docker hosts on your local Mac or Windows box, on your company network, in your data center, or on cloud providers like Azure, AWS, or Digital Ocean.

Using docker-machine commands, you can start, inspect, stop, and restart a managed host, upgrade the Docker client and daemon, and configure a Docker client to talk to your host.

Point the Machine CLI at a running, managed host, and you can run docker commands directly on that host. For example, run docker-machine env default to point to a host called default, follow on-screen instructions to complete env setup, and run docker ps, docker run hello-world, and so forth.

Machine was the only way to run Docker on Mac or Windows previous to Docker v1.12. Starting with the beta program and Docker v1.12, Docker for Mac and Docker for Windows are available as native apps and the better choice for this use case on newer desktops and laptops. We encourage you to try out these new apps. The installers for Docker for Mac and Docker for Windows include Docker Machine, along with Docker Compose.

Building a test docker swarm cluster

#!/usr/bin/env bash

for node in ds-manager, ds-worker; do
  docker-machine create -d virtualbox ${node}
done

# init swarm on ds-manager
managerip=$(docker-machine ip ds-manager)
docker-machine ssh ds-manager docker swarm init --advertise-addr ${managerip}
jointoken=$(docker-machine ssh ds-manager docker swarm join-token worker)

docker-machine ssh ds-worker swarm join --token ${jointoken ${managerip}:2377

At this moment we should have 2 dockerhosts. 1 as manager and the other as worker node. With the use of docker-machine we can also connect the docker client to the dockerhost.

eval $(docker-machine env ds-manager)

After this is done, all docker action from you local system will be done on the dockerhost ds-manager. If you need to run a docker command on you local system, and not in on the dockerhost ds-manager you need to run the following command.

eval $(docker-machine env -u)