Sharing thoughts on being a maker and sometime breaker of tech along with other interests such as electronics, photography, films and running.
Opinions are my own...unless pilfered from someone smarter, better looking or can do more push-ups.
Configuring and working with Docker Machine
Dec 17, 2016
- docker
Docker Machine is a component of Docker that allows management of remote virtual machines hosting docker containers. This post covers on overview of Docker Machine and some handy commands to configure and manage it.
Commands
Some of the commands covered in this post include:
docker-machine ls
- Lists configured remote hostsdocker-machine create
- Creates a new remote hostdocker-machine env
- Displays environment variables for the remote hostdocker-machine ip
- Displays the Ip Address of the remote host
This is the complete list of Docker Machine commands available from the command line.
Examples
docker-machine ls
docker-machine create --driver hyperv manager1
docker-machine env manager1
docker-machine ip manager1
And, the environment variables used by the local docker engine to communicate with a remote host
Listing the configured machines
docker-machine ls
Create a new docker machine
This command creates a new docker machine host using the HyperV driver (on Windows) and names it manager1. It downloads and uses a basic OS image Boot2Docker to use as an operating system for the machine and configures a network and SSH for connections.
docker-machine create --driver hyperv manager1
Configuring your local shell
docker machine env
is used to provide the details required for the local docker to configure management of the new machine. It provides a set of environment variables that can be configured in the shell. Without these, Docker won’t know which remote host you wish to use.
In order to see the environment variables to set for manager1, run the following.
docker-machine env manager1
When running this from the Windows Command Prompt, it will output:
The last line in the output can be executed in order to actually set the environment variables.
@FOR /f "tokens=*" %i IN ('docker-machine env manager1') DO @%i
Testing the setup
To ensure everything is set up correctly, a container can be run against the remote host.
docker run --rm busybox echo hello world
You’ll notice the remote host wasn’t mentioned in the command. The local Docker Engine will use the environment variable DOCKER_MACHINE_NAME
to know which machine to interact with.
Other useful commands
This displays the IP address of manager1
docker-machine ip manager1
Alternatively, to see the currently configured machine that docker will communicate with
echo %DOCKER_MACHINE_NAME%
docker-machine ip %DOCKER_MACHINE_NAME%