DigitalOcean

To launch a Docker host in DigitalOcean using Docker Machine, you only need an API access token. Rather than explaining how to generate one here, you can follow the instructions at https://www.digitalocean.com/help/api/.

Launching a Docker host using the API token will incur cost; ensure you keep track of the Docker hosts you launch. Details on DigitalOcean's pricing can be found at https://www.digitalocean.com/pricing/. Also, keep your API token secret as it could be used to gain unauthorized access to your account. All of the tokens used in this chapter have been revoked.
Due to the additional flags that we need to pass to the Docker Machine command, I will be using to split the command across multiple lines to make it more readable.

To launch a Docker host called docker-digtialocean, we need to run the following command:

$ docker-machine create 
--driver digitalocean
--digitalocean-access-token ba46b9f97d16edb5a1f145093b50d97e50665492e9101d909295fa8ec35f20a1
docker-digitalocean

As the Docker host is a remote machine, it will take a little while to launch, configure, and be accessible. As you can see from the following output, there are also a few changes to how Docker Machine bootstraps the Docker host:

Running pre-create checks...
Creating machine...
(docker-digitalocean) Creating SSH key...
(docker-digitalocean) Creating Digital Ocean droplet...
(docker-digitalocean) 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-digitalocean

Once launched, you should be able to see the Docker host in your DigitalOcean control panel:

 

Reconfigure your local client to connect to the remote host by running:

$ eval $(docker-machine env docker-digitalocean)

Also, you can run docker version and docker-machine inspect digitalocean to find out more information about the Docker host.

Finally, running docker-machine ssh docker-digitalocean will SSH you into the host; as you can see from the following output and also from the output when you first launched the Docker host, there is a difference in the operating system used:

As you can see, we didn't have to tell Docker Machine which operating system to use, the size of the Docker host, or even where to launch it. That is because each driver has some pretty sound defaults. Adding these defaults to our command makes it look like the following:

$ docker-machine create 
--driver digitalocean
--digitalocean-access-token ba46b9f97d16edb5a1f145093b50d97e50665492e9101d909295fa8ec35f20a1
--digitalocean-image ubuntu-16-04-x64
--digitalocean-region nyc3
--digitalocean-size 512mb
--digitalocean-ipv6 false
--digitalocean-private-networking false
--digitalocean-backups false
--digitalocean-ssh-user root
--digitalocean-ssh-port 22
docker-digitalocean

As you can see, there is scope for you to customize the size, region, operating system, and even networking your Docker host is launched with.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset