Docker Machine

Docker Machine is a tool for provisioning and managing your Dockerized hosts (hosts with Docker Engine on them).

Docker Machine is used to create Docker hosts on your local Mac or Windows box, on your company network, in your data center, or on cloud providers like AWS

Installation

Install in Linux

1
2
3
$ base=https://github.com/docker/machine/releases/download/v0.16.0 &&
curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&
sudo install /tmp/docker-machine /usr/local/bin/docker-machine

To check installation

1
$ docker-machine version

Create a machine

Create a machine. -d/--driver flag is required to indicate the provider(VirtualBox, DigitalOcean, AWS, etc.)

1
docker-machine create --driver virtualbox mydockervm

Note: the hostname is ‘mydockervm’.

output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
......
Creating machine...
(mydockervm) Copying /home/xing/.docker/machine/cache/boot2docker.iso to /home/xing/.docker/machine/machines/mydockervm/boot2docker.iso...
(mydockervm) Creating VirtualBox VM...
(mydockervm) Creating SSH key...
(mydockervm) Starting the VM...
(mydockervm) Check network to re-create if needed...
(mydockervm) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env mydockervm

Inspect Machine

1
docker-machine inspect mydockervm

List Machines

1
docker-machine ls

output

1
2
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
mydockervm - virtualbox Running tcp://192.168.99.100:2376 v18.09.1

SSH to the machine

First use docker-machine env command to set the envir

1
docker-machine env mydockervm

Then ssh to the machine. use exit command to exit the docker-machine

1
docker-machine ssh mydockervm

Stop the machine

This will powerdown the machine

1
docker-machine stop mydockervm

Remove the machine

```
docker-machine rm mydockervm

Reference