Launch Docker VM on Digital Ocean

August 26, 2020

Tags: digital ocean, ssh

Revised article

(Update: 2020-09-05) A previous version of this article described using Docker Machine to solve this problem. As far as I can see, Docker Machine is no longer the recommended way of doing anything, as most if not all of its functionality has been integrated into other products. To launch droplets from the terminal, the current recommended way of doing so is through the doctl CLI.

I’m looking to run a docker project on Digital Ocean. I could launch an Ubuntu droplet from the web interface and setup a Docker host on that, but I’d much rather run everything from the command line to make it easily repeatable.

To do that, we need a Digital Ocean token, so we head to the Digital Ocean API tokens page to create a new one.

Digital Ocean create API token

We’ll use this shortly.

Install doctl

Digital Ocean has released doctl, a CLI which is a wrapper around their REST API. It can be installed with homebrew:

$ brew install doctl

Authenticate with doctl using the following command, and paste in your token from the previous section:

$ doctl auth init

Please authenticate doctl for use with your DigitalOcean account. You can generate a token in the control panel at

Enter your access token:
Validating token... OK

Start by checking the hosts’ statuses:

$ doctl compute droplet list
ID           Name              Public IPv4       Private IPv4    Public IPv6    Memory    VCPUs    Disk    Region    Image                                     VPC UUID    Status    Tags    Features          Volumes
******       ancient-server                                   512       1        20      sgp1      Ubuntu             2020-08-17                         active            backups,virtio
*********    docker-droplet    xxx.xx.37.221                                    1024      1        25      fra1      Ubuntu Docker 19.03.12 on Ubuntu 20.04                active

Now we can try and create a new VM. Like this one Docker Droplet.

$ doctl compute droplet create <name> --region <region-slug> --image <image-slug> --size <size-slug>

Or, in my particular case:

$ doctl compute droplet create DropletName \
    --region Fra1 \
    --image docker-20-04 \
    --size s-1vcpu-1gb \
    --ssh-keys 44:03:1b:13:dc:93:...

Note: if the ssh-keys is not passed, the root password for your droplet will be sent to your e-mail address. If ssh keys are set up correctly, logging in is as simple as:

$ doctl compute ssh DropletName

If this doesn’t work, check that your ssh fingerprints match those saved in your Digital Ocean account:

$ doctl compute ssh-key list
ID          Name                          FingerPrint
28285948    new-cert                      44:03:1b:13:dc:93:...
639996      AAAAB3NzaC1yc2EAAAADAQA...    d5:9d:74:41:1c:e6:...
$ ssh-keygen -l -E md5 -f ~/.ssh/
3072 MD5:44:03:1b:13:dc:93:... lasper@dashou.local (RSA)

In the above, the public key ~/.ssh/id_rsa matches the new-cert in my Digital Ocean account. If it doesn’t, go ahead and add your current key to Digital Ocean and create the droplet again.

Deleting a droplet follows the same pattern:

$ doctl compute droplet delete DropletName