Now a PWD driver for Docker Machine
Docker Machine is a great tool to create Docker hosts (nodes running the Docker daemon) locally (through VirtualBox) or on cloud providers (AWS, GCE, DigitalOcean, Azure, Rackspace, …). It’s now possible to use it to create temporary hosts on PWD, the excellent online Docker playground. This was announced at DockerCon 2017 by @marcosnils and @xetorthio, PWD’s creators (on the picture above). BTW… you rock guys :)
For those who do not know PWD (Play With Docker), it’s an online Docker playground available at http://play-with-docker.com where one can do almost anything with Docker from a web browser. At the origin, its main purpose was to avoid the provisioning of several VMs for each participant of Jerôme Petazzoni’s great orchestration workshop. Setting up 5 VMs per participants can be quite a hassle when there are scores of them.
From PWD, one can use the Docker CLI to create images, containers, networks, volumes, and to play with Swarm, Docker’s embedded orchestration solution.
The screenshot below illustrates the result of the creation of a 3 nodes Swarm cluster using PWD, the whole things took less than 2 minutes.
We created 3 instances (maximal number is 5 instances per session, each session times out after 4 hours), initiated the Swarm form the first node (using docker swarm init command) and joined the second and third node to the swarm with docker swarm join command specified in the initialisation’s output. Yes, it’s really as easy as this.
You want to test a web service ? Run a container within PWD and you get the port exposed automatically (have you noticed the 8080 link, in the right panel, below the instance name ?).
Clicking on this link opens the default nginx index.html.
Behind the hood
PWD is built in Go, and it’s running DinD (Docker in Docker). That means each instance, which is based on an Alpine container, embeds a Docker daemon and a Docker client (on top of some other useful binaries and librairies).
Docker Machine is a really cool tool of the Docker ecosystem, it exists since quite some time, and allows to create a Docker host with a one-liner. It only needs to be given the name of a driver and a couple of options related to the driver selected.
You need to create a VM running Docker on your local VirtualBox, no problem, the following command will do the trick:
$ docker-machine create -d virtualbox node1
Do you want to create the second node on DigitalOcean (let’s be crazy) here we go:
$ docker-machine create -d digitalocean --digitalocean-access-token $TOKEN node2
Note: when cloud providers come to the picture, we need to provide credentials in one way or another, in the DigitalOcean example command, it’s provided through the TOKEN environment variable.
Docker Machine with PWD driver
We’ll see now how a new PWD’s instance can be created from our local command line using Docker Machine.
As prerequisites, make sure you are running the last version of Go (1.8.1 currently) and install the pwd driver.
$ go version
go version go1.8.1 darwin/amd64
$ go get github.com/franela/docker-machine-driver-pwd
Once this is done, let’s get the session URL of PWD and export it into the PWD_URL environment variable.
$ export PWD_URL=”http://host3.labs.play-with-docker.com/p/4b0cb8e8-9d33-4b03-be0d-b50988a8a5c6#4b0cb8e8_node1"
We can now ask Docker Machine to create a new host, node4, using the pwd driver.
$ docker-machine create -d pwd node4
Running pre-create checks…
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env node4
As the screenshot above shows, node4 has been created and is running peacefully on PWD.
From our local CLI, we can now target this guy and send it Docker commands.
$ eval $(docker-machine env node4)
$ docker images ls
REPOSITORY TAG IMAGE ID CREATED SIZE
Note: instead of specifying PWD session through the PWD_URL environment variable we could use the --pwd-url option of the Docker Machine’s pwd driver.
Why is this great ?
Some weeks ago I gave a Docker training, each participants used a Windows 10 machine with Docker for Windows. Everything was fine until we got to the Docker Machine stuff and realized it was not possible (that is probably fixed now) to create new hosts on VirtualBox when HyperV is activated, nor was it possible to create new working HyperV hosts. Using Docker Machine’s pwd driver would have made the thing easier and this is the way I’ll go next time.
Wait, there is more…
PWD is open source, that means we can clone it and install it wherever we want. We can also be sure it will run the last version of Docker CE edge so you can test all the latest exciting stuff :)
I love this platform, very user friendly and so handy for training purposes.