Now that we can deploy Docker hosts locally and to the cloud environments, we need to know how we can manage and manipulate these Docker hosts. Let's take a look at all the commands Docker Machine has to offer.
On running the docker-machine create
command, you should receive an output similar to this:
INFO[0041] To point your Docker client at it, run this in your shell: $(docker-machine env dev2)
This is how you can set the default to target Docker hosts with Docker Machine. Keep this in mind, when we are looking at the following commands:
config
env
inspect
kill
restart
rm
start
stop
active
ip
ls
scp
ssh
upgrade
url
TLS
Of these commands, the first eight commands are already covered in Chapter 2, Up and Running. Let's take a look at the rest.
You can use the active
subcommand to see which Docker host is currently active and commands that you execute will be executed on that Docker host:
$ docker-machine active dev2
The ip
subcommand will give you the IP address of the active host you are pointing to with Docker Machine:
$ docker-machine ip <name> 192.168.50.158
You can use the ls
subcommand to view all the running Docker hosts you have used to create with Docker Machine. The information will include:
Let's take a look at a sample command output when you use docker-machine ls
:
$ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM dev virtualbox Stopped dev2 * vmwarefusion Running tcp://192.168.50.158:2376
As you can see, you get the list of Docker hosts you can control. As well as the driver, its state, URL, and its part of a Swarm cluster.
There are multiple ways to use the Docker Machine scp
command. You can copy files or folders from the local host to a Docker host:
$ docker-machine scp <file_name> <name>:/<path>/<to>/<folder>/
It can be copied from one machine to another:
$ docker-machine scp <host1>:/<path>/<to>/<file> <host2>:/<path>/<to>/<folder>/
It can also be copied from the machine back to the host:
$ docker-machine scp <name>:/<path>/<to>/<file> .
You can SSH into your Docker hosts as well by using the ssh
subcommand. This can be useful if you need to troubleshoot why the commands you push against your hosts might not be working:
$ docker-machine ssh <name>
If you have a Docker host that is running Docker version 1.7 (let's say) and you want to upgrade it to the latest version, you could use the upgrade
subcommand of Docker Machine:
$ docker-machine upgrade <name>
This will upgrade the version of Docker that is running on the Docker hostname you provide.
The url
subcommand will give you the URL that is being used for communication for the Docker host:
$ docker-machine url <name> tcp://192.168.50.158:2376
Docker Machine also has the option to run everything over TLS. This is the most secure way of using Docker Machine to manage your Docker hosts. This setup can be tricky if you start using your own certificates. By default, Docker Machine stores your certificates that it uses in /Users/<user_id>/.docker/machine/certs/
. You can view these items simply by running:
$ docker-machine --help
This will give you a global Options
section at the bottom of the listing that lists this information. These are the locations of the intermediate certificate, intermediate key, and the certificate that Docker Machine uses as well as its corresponding key. You would need to update these files with your own certificates if you don't want to be using the self-signed certificates that Docker Machine creates.