← back to the blog

Install docker machine on Ubuntu 18

on October 12th, 2018 by Chanoch

Download docker-machine

wget https://github.com/docker/machine/releases/download/v0.15.0/docker-machine-$(uname -s)-$(uname -m)

Rename and make executable

mv docker-machine-Linux-x86_64 docker-machine && chmod +x docker-machine

Test install

./docker-machine version

Move it somewhere permanent

sudo mkdir /opt/docker && sudo chmod myuser:mygroup -R /opt/docker && chown u+w /opt/docker && sudo chmod rx+og && mv ./docker-machine /opt/docker/

Add it to somewhere in your PATH:

sudo ln -s /opt/docker/docker-machine /usr/local/bin/

I also like to simplify calling it by providing an alias for it called machine

Retest Install

docker-machine version

Install command a bash prompt script which shows the active docker machine

The first script customises the bash prompt to show the active machine


sudo wget https://raw.githubusercontent.com/docker/machine/master/contrib/completion/bash/docker-machine-prompt.bash -O /etc/bash_completion.d/docker-machine-prompt.bash

$(__docker_machine_ps1 " [%s]") to your .bashrc before the \$ or $PS1 of the three lines which begin with PS1 (color terminal, mono and xterm). You can find them in nano by searching for PS1 with Ctrl-W to find the first, then Alt-W to find the others (although they are near each other)

Reload bash:

source ~/.bashrc

Install a script which allows you to easily switch between hosts

sudo wget https://raw.githubusercontent.com/docker/machine/master/contrib/completion/bash/docker-machine-wrapper.bash -O /etc/bash_completion.d/docker-machine-wrapper.bash

Install tab completion for dockert-machine commands

sudo wget https://raw.githubusercontent.com/docker/machine/master/contrib/completion/bash/docker-machine.bash -O /etc/bash_completion.d/docker-machine.bash

Create a Digital Ocean personal access token and add it to .bashrc

nano ~/.bashrc
# the digital ocean docker machine token to remotely manage docker hosts
export DIGITAL_OCEAN_API_TOKEN=fdsfdsfdsfds

Save and close

source ~/.bashrc

Check the variable is listing


Create a machine

machine create --driver digitalocean --digitalocean-image ubuntu-18-04-x64 --digitalocean-access-token $DIGITAL_OCEAN_API_TOKEN docker-1

Inspect the machine

machine inspect docker-1

machine config docker-1

machine ip docker-1

machine ls

Switch to the machine

docker-machine use docker-1

Exit from a machine

docker-machine use -u