Tutorial

How To Provision and Manage Remote Docker Hosts with Docker Machine on Ubuntu 16.04

How To Provision and Manage Remote Docker Hosts with Docker Machine on Ubuntu 16.04
Not using Ubuntu 16.04 ? Choose a different version or distribution.
Ubuntu 16.04

Introduction

Prerequisites

  • How To Install and Use Docker on Ubuntu 16.04 for instructions)
  • A DigitalOcean API token. If you don’t have one, generate it using this guide . When you generate a token, be sure that it has read-write scope. That is the default, so if you do not change any option while generating it, it will have read-write capabilities. To make it easier to use on the command line, be sure to assign the token to a variable as given in that article.
  • Step 1 — Installing Docker Machine on Your Local Computer

            1. Step 2 — Installing Additional Docker Machine Scripts

                    1. Step 3 — Provisioning a Dockerized Host Using Docker Machine

                              1. Step 4 — Specifying the Base OS When Creating a Dockerized Host

                                    1. DigitalOcean API documentation.

                                      For example, to provision a machine with 2 GB of RAM, two CPUs, and a 60 GB SSD, use the slug s-2vcpu-2gb:

                                        1. Step 5 — Executing Additional Docker Machine Commands

                                                          1. Step 6 — Executing Commands on a Dockerized Host via SSH

                                                                  1. Step 7 — Activating a Dockerized Host

                                                                      1. Step 8 — Creating Docker Containers on a Remote Dockerized Host

                                                                            1. Step 9 — Disabling Crash Reporting (Optional)

                                                                              1. Conclusion

                                                                                official documentation page. The three Bash scripts downloaded in this tutorial are hosted on this GitHub page.


    finid

    author



    Still looking for an answer?

    Ask a question Search for more help

    Was this helpful?
    10 Comments
    

    This textbox defaults to using Markdown to format your answer.

    You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

    Sign In or Sign Up to Comment

    This guide appears to be out of date. Not sure if there are any newer ones on this site, but following it and running the command:

    docker-machine create --driver digitalocean --digitalocean-access-token $DOTOKEN ubuntu1604-docker
    

    resulted in

    Error creating machine: Error in driver during machine creation: POST https://api.digitalocean.com/v2/droplets: 422 You specified an invalid image for Droplet creation.
    

    To fix it, I followed the official Docker guide on DigitalOcean usage with Ubuntu here, using the command:

    curl -L https://github.com/docker/machine/releases/download/v0.10.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine &&
      chmod +x /tmp/docker-machine &&
      sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
    

    docker-machine: ‘use’ is not a docker-machine command. See ‘docker-machine --help’.

    Mark Veenstra July 26, 2019

    According to the docs it is not possible to set the project where the droplets will be created. So the default project is used to deploy the droplets on.

    Any change it could be set by a preference?

    When I run docker-machine create, I get an error. Here’s output with debug turned on. The machine-name is ‘docker-registry’. Command

    docker-machine create --driver digitalocean --digitalocean-image ubuntu-18-04-x64 --digitalocean-access-token $DOTOKEN docker-registry
    

    Error

    checking docker daemon
    (docker-registry) Calling .GetSSHHostname
    (docker-registry) Calling .GetSSHPort
    (docker-registry) Calling .GetSSHKeyPath
    (docker-registry) Calling .GetSSHKeyPath
    (docker-registry) Calling .GetSSHUsername
    Using SSH client type: external
    Using SSH private key: /home/kobenauf/.docker/machine/machines/docker-registry/id_rsa (-rw-------)
    &{[-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 [email protected]
    3.66.142 -o IdentitiesOnly=yes -i /home/kobenauf/.docker/machine/machines/docker-registry/id_rsa -p 22] /usr/bin/ssh <nil>}
    About to run SSH command:
    sudo docker version
    SSH cmd err, output: exit status 1: sudo: docker: command not found
    Error getting SSH command to check if the daemon is up: ssh command error:
    command : sudo docker version
    err     : exit status 1
    output  : sudo: docker: command not found
    

    Earlier in the output I noticed:

    About to run SSH command:
    if ! type docker; then curl -sSL https://get.docker.com | sh -; fi
    SSH cmd err, output: <nil>: bash: line 0: type: docker: not found
    

    When I run just curl -sSL https://get.docker.com it tells me the certificate has expired. It seems that is causing docker not to install and the rest to fail.

    Thanks great article…but how do you connect to your swarm from yet another machine ? i would imagine something like eval $(docker-machine env production-manager-1) but the new machine has no knowledge of what production-manager-1 is.

    I followed the steps but it didn’t work at first, I got this when running the docker-machine create command:

    Error creating machine: Error in driver during machine creation: POST https://api.digitalocean.com/v2/droplets: 422 You specified an invalid image for Droplet creation.
    

    So I created the machine specifying the ubuntu image explicitly:

    docker-machine create --driver digitalocean --digitalocean-image ubuntu-16-04-x64 --digitalocean-access-token $DOTOKEN ubuntu-docker-test
    

    I got past the error to get this new output:

    Running pre-create checks...
    Creating machine...
    (ubuntu1604-docker) Creating SSH key...
    (ubuntu1604-docker) Creating Digital Ocean droplet...
    (ubuntu1604-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...
    Error creating machine: Error running provisioning: ssh command error:
    command : sudo systemctl -f start docker
    err     : exit status 1
    output  : Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
    

    According to this thread this is apparently related to a version mismatch problem so I provisioned the machined using the command specified in the thread:

    docker-machine create --driver digitalocean --digitalocean-image ubuntu-16-04-x64 --digitalocean-access-token $DOTOKEN --engine-install-url=https://web.archive.org/web/20170623081500/https://get.docker.com ubuntu1604-docker-new
    

    After this, the machine got successfully created.

    Thank you for the tutorial, it’s very easy to follow and works perfectly.