Using Docker-Machine with CloudShare
To get articles like this free in your inbox, subscribe to our newsletter.

Docker-Machine lets you run Docker commands on remote hosts. It integrates with all the popular cloud providers, and as of today, this includes CloudShare.
Docker-Machine?
Yes, Docker-Machine. You know – that thing everyone used for a while to run Docker on Macs, before Docker for Mac was released? It is a tremendously useful and underappreciated part of the Docker tool chain.
Here’s what Docker-Machine does for you.
Docker-Engine (the bit that actually runs the containers) is actually an HTTP API server. When you do something like docker container ls
, for example, the CLI application sends a HTTP GET /containers/json
request to get you the data. Now, typically this happens locally, on a unix socket. But the Docker-Engine daemon can happily listen on a TCP socket as well, accepting requests from remote machines. The DOCKER_HOST
env-var tells the CLI which Docker-Engine daemon it should use.
Thus, if you want to run Docker commands on a remote machine, you can. But you need to set the right env-vars, make sure the right Docker-Engine version is available on the remote machine, and perform authentication – a bunch of stuff, I know, but this is exactly the hassle Docker-Machine eliminates for you.
Remote Docker
Let’s say you have a Dockerized web server (my-node-server
) that you wish to run on a remote machine that’s publicly accessible on the web. With Docker-Machine you can do something like:
docker-machine create --driver cloudshare my-server
This creates a remote VM for you, installs Docker on it, and configures authentication. Then you just “activate” it with:
eval $(docker-machine env my-server)
which sets the proper env-vars for you. And that’s it. From that point on any docker command you run happens remotely:
docker run my-node-server
Behind the scenes, CloudShare’s Docker-Machine driver spins up a new environment for you that already has the latest Docker-Engine driver installed.
The Cool Part
When you use CloudShare’s Docker-Machine driver, you get a fresh, disposable VM on which to run containers. This way, your developer machine doesn’t get bogged down and clogged up by all those containers and images.
Each VM runs in its own environment, which you can snapshot, restore and share with others. You can use that to capture the entire machine’s state, for example, if you come across some bug that’s hard to reproduce.
Furthermore, each VM is accessible on the internet and has a fixed public DNS record. If you are serving HTTP, you also get HTTPS termination for free using the web access feature. You could have properly secured HTTPS server online in minutes, without having to mess around with cerficiates.
You can spin up as many of these Docker machines as you need, and with CloudShare’s auto-suspend policies you only pay for actual usage. When a CloudShare docker-machine is docker-idle (without any running containers), it will auto-suspend itself after a while. This is configurable with environment policies, but works well out of the box.
Getting Started
- You’ll need to install Docker-Machine.
- Download the latest release of the CloudShare driver for Docker-Machine and put the executable (
docker-machine-driver-cloudshare
) somewhere in your$PATH
. It’s written in Go, using our Go SDK, so it’s just a single binary – no other dependencies.
Now try calling:
docker-machine -d cloudshare create --help
If it prints the usage, you’re set.
Usage: docker-machine create [OPTIONS] [arg...]
Create a machine
Description:
Run 'docker-machine create --driver name' to include the create flags for that driver in the help text.
Options:
--cloudshare-api-id CloudShare API ID (required) [$CLOUDSHARE_API_ID]
--cloudshare-api-key CloudShare API KEY (required) [$CLOUDSHARE_API_KEY]
--cloudshare-cpus "0" CPU count
--cloudshare-disk-gb "0" Disk size (GB), >=10GB
--cloudshare-ram-mb "0" RAM (MBs) 256-32768
--cloudshare-region-name "Miami" CloudShare region name
--cloudshare-vm-template-id VM Template ID
--cloudshare-vm-template-name "Docker - Ubuntu 14.04 Server - SMALL" VM Template name (exact name; cannot be used with --cloudshare-vm-template-id)
- The only required option is the API ID & Key. We recommend you export them as env-vars (
CLOUDSHARE_API_ID, CLOUDSHARE_API_KEY
) so you don’t have to pass them into each call.
You can now create Docker machines with:
docker-machine create -d cloudshare machine-name
Easy, right? Try doing the same with the amazonec2
Docker-Machine driver and see how long that takes to work? 😉
Getting Fancy
We have a few Docker-ready VM templates you can choose from, with different hardware specs and OS versions.
By default the driver launches a “small” VM, but you can use --cloudshare-vm-template-name
to specify a different template. For example:
docker-machine create -d cloudshare \
--cloudshare-vm-template-name "Docker - Ubuntu 16.04 Server - LARGE" \
my-large-machine
You can also tweak the hardware specs yourself (cpus, RAM, disk), but be aware it takes longer to launch customized VMs than when using one of the ready-made templates.
Read our blog post about Docker 1.13
You may also be interested in reading about:
What you should do next…
1. Subscribe to our newsletter:
Subscribe to our newsletter below for the latest news, advice and thought-leadership for software professionals. Or visit our blog to browse our most recent articles.
2. Learn how virtual labs can grow your business:
To learn more about how CloudShare helps software organizations grow revenue, increase efficiency and improve quality, visit our resources page. You’ll be able to browser dozens of valuable white papers, eBooks, webinars, case studies, and brochures.
3. Get a FREE, no obligation demo:
Discover just how easy it is to create your cloud environment—in minutes! One of our friendly virtual labs experts will be happy to:
- Show you the platform in action
- Calculate pricing for your business
- Set you up with a 14-day free trial
- Answer any questions you have
- No pressure or obligation