Using Docker Machine to provision hosts on cloud providers with U$ 5 per month
Docker Machine driver plugins are available for many cloud platforms, so you can use Machine to provision cloud hosts. When you use Docker Machine for provisioning, you create cloud hosts with Docker Engine installed on them.
You’ll need to install and run Docker Machine, and create an account with the cloud provider.
Then you provide account verification, security credentials, and configuration options for the providers as flags to docker-machine create
. The flags are unique for each cloud-specific driver. For instance, to pass a Digital Ocean access token you use the --digitalocean-access-token
flag. Take a look at the examples below for Digital Ocean and Vultr.
Digital Ocean*
For Digital Ocean, this command creates a Droplet (cloud host) called “docker-digital”.
# docker-machine create --driver digitalocean --digitalocean-access-token **********************754d docker-digital
Running pre-create checks...
Creating machine...
(docker-digital) Creating SSH key...
(docker-digital) Creating Digital Ocean droplet...
(docker-digital) Waiting for IP address to be assigned to the Droplet...
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 ubuntu(systemd)...
Installing Docker...
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 docker-digital
For a step-by-step guide on using Machine to create Docker hosts on Digital Ocean, see the Digital Ocean Example.
Vultr*
For Vult , this command creates an instance called “docker-vultr”:
# docker-machine create --driver vultr --vultr-api-key=***********************SWNMA docker-vultr
Running pre-create checks...
(ubuntu-machine) Validating Vultr VPS parameters...
Creating machine...
(ubuntu-machine) Creating Vultr VPS
(ubuntu-machine) Using PXE boot
(ubuntu-machine) Provisioning RancherOS (v1.0.2). SSH user set to 'rancher'.
(ubuntu-machine) Waiting for IP address to become available...
(ubuntu-machine) Created Vultr VPS ID: 11709474, Public IP: 108.61.87.40, Private 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 rancheros...
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 docker-vultr
For a step-by-step guide on using Machine to create Dockerized Vultr instances, see the Vultr configuration here.
Vultr now accepts Bitcoin for payment of cloud hosting services.
Done!
# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
docker-digital - digitalocean Running tcp://104.131.20.48:2376 v17.10.0-ce
docker-vultr - vultr Running tcp://108.61.87.47:2376 v17.03.1-ce
Removing a machine…
Remove a machine. This will remove the local reference as well as delete it on the cloud provider or virtualization management platform.
# docker-machine rm docker-digital docker-vultr
About to remove docker-digital, docker-vultr
WARNING: This action will delete both local reference and remote instance.
Are you sure? (y/n): y
Successfully removed docker-digital
Successfully removed docker-vultr
The docker-machine create command
The docker-machine create
command typically requires that you specify, at a minimum:
--driver
- to indicate the provider on which to create the machine (VirtualBox, DigitalOcean, AWS, and so on)- Account verification and security credentials (for cloud providers), specific to the cloud service you are using
<machine>
- name of the host you want to create
For convenience, docker-machine
will use sensible defaults for choosing settings such as the image that the server is based on, but you override the defaults using the respective flags (e.g. --digitalocean-image
). This is useful if, for example, you want to create a cloud server with a lot of memory and CPUs (by default docker-machine
creates a small server).
For a full list of the flags/settings available and their defaults, see the output of docker-machine create -h
at the command line, the create command in the Machine command line reference, and driver options and operating system defaults in the Machine driver reference.
Drivers for cloud providers
When you install Docker Machine, you get a set of drivers for various cloud providers (like Amazon Web Services, Vultr, Digital Ocean, or Microsoft Azure) and local providers (like Oracle VirtualBox, VMWare Fusion, or Microsoft Hyper-V).
See Docker Machine driver reference for details on the drivers, including required flags and configuration options (which vary by provider).
3rd-party driver plugins
Several Docker Machine driver plugins for use with other cloud platforms are available from 3rd party contributors. These are use-at-your-own-risk plugins, not maintained by or formally associated with Docker. See Available driver plugins.
Save Money and Enjoy :)