Digital Ocean Docker Machine Setup

To do a Digital Ocean Docker Machine Setup  Docker Machine makes your live really easy. Here is how your can provision and deploy with your docker-machine.

FYI

If you have the Docker Client (Engine) installed on your Mac, Linux Box or PC you should have docker-machine available already. See more information on this at Docker.

Trials on Existing Droplet

Without a driver for an already existing host – Digital Ocean Docker setup I tried the following:

docker-machine env larastudio
Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "xxx.xxx.xx.xxx": dial tcp: address xxx.xxx.xx.xxx: missing port in address
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.
Be advised that this will trigger a Docker daemon restart which might stop running containers.

So once I checked the setup one I was told the certs could not be checked. So I tried regerating them.<pre>

jasper@~/code/domain.com/laradock $ docker-machine regenerate-certs larastudio
Regenerate TLS machine certs? Warning: this is irreversible. (y/n): y
Regenerating TLS certificates
Waiting for SSH to be available...
Too many retries waiting for SSH to be available. Last error: Maximum number of retries (60) exceeded

Then did a:

docker-machine -D env larastudio

for a more detailed report. I got more errors

Getting to WaitForSSH function...
(larastudio) Calling .GetSSHHostname
(larastudio) Calling .GetSSHPort
(larastudio) Calling .GetSSHKeyPath
(larastudio) Calling .GetSSHUsername
Using SSH client type: external
&{[-F /dev/null -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none @ -p 0] /usr/bin/ssh }
About to run SSH command:
exit 0
SSH cmd err, output: exit status 255: usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
           [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]

Error getting ssh command 'exit 0' : ssh command error:
command : exit 0
err     : exit status 255
output  : usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
           [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]


Then I found a thread with a more detailed command that seemed to be better.

docker-machine create --driver generic --generic-ip-address xxx.xxx.xx.xxx --generic-ssh-user root larastudio

and it was able to connect, but I got a

Running pre-create checks...
Creating machine...
(larastudio) No SSH key specified. Assuming an existing key at the default location.
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)...
Error creating machine: Error running provisioning: ssh command error:
command :
if ! grep -xq '.*\slarastudio' /etc/hosts; then
if grep -xq '127.0.1.1\s.*' /etc/hosts; then
sudo sed -i 's/^127.0.1.1\s.*/127.0.1.1 larastudio/g' /etc/hosts;
else
echo '127.0.1.1 larastudio' | sudo tee -a /etc/hosts;
fi
fi
err : exit status 255
output :

Update: Read in this Digital Ocean thread that you can do it, but you need to be more specific about the ssh user and ssh key you use as well as having port 2376 open. Command I needed was:

docker-machine create \
    --driver=generic \
    --generic-ip-address=IP_ADDRESS \
    --generic-ssh-user=USERNAME \
    --generic-ssh-key=PATH_TO_SSH_KEY \
    --generic-ssh-port=PORT \
        MACHINE_NAME

 

Provisioning New Droplet

Then I realized it was not working on a machine that was already up and running with Docker. So I did a:

docker-machine create --driver digitalocean --digitalocean-access-token 1111111 domain-docker

and that worked:

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

But I did not use enough parameters so I got a 1GB Droplet at the NYC zone. So I did a

docker-machine create --driver digitalocean -h

to see all options. And I saw I could use

  • –digitalocean-region “ams2”
  • –digitalocean-ipv6
  • –digitalocean-size “s-1vcpu-1gb”

among others. So I did a

docker-machine create --driver digitalocean --digitalocean-region "ams2" --digitalocean-ipv6 --digitalocean-monitoring --digitalocean-access-token 1111111 domain-docker

and that worked even better.

Working on the Remote Machine

Then to do work on that machine you can do

eval $(docker-machine env machine-name)

and start running docker-compose and docker commands on the remote server. FYI docker-compose did not get installed on the remote for some reason. So that you can only use locally.

Docker Machine Envs

To check what envs are being used you can do a

env | grep DOCKER

You will then see how things are setup. This so you know where you are working or what you are working on. And these details you can use to remove them or unset them. You can check your envs to unset with

docker-machine env -u

To return to localhost for docker you can do a

eval $(docker-machine env -u)

SSH Remote Machine

You can also ssh into the box using

 docker-machine ssh box

And as stated you can access the machine that way. FYIs, ssh-ing as root does no longer seems to work and as stated docker-compose is not installed on the DO Droplet.

Tagged in : Tagged in :
Jasper Frumau

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.