Why should I use Docker-machine
I have an older desktop system and want to run Docker on Mac or Windows
Installing Docker Machine on a Mac or Windows box with the Docker Toolbox installer provisions a local virtual machine with Docker Engine, gives you the ability to connect it, and run docker
commands.
I want to provision Docker hosts on remote systems
If you have a Linux box as your primary system, and want to run docker
commands, all you need to do is download and install Docker Engine. However, if you want an efficient way to provision multiple Docker hosts on a network, in the cloud or even locally, you need Docker Machine.
Installing Docker-Machine
Install Docker
Download the Docker-machine binary and extract it to your PATH.
MacOS:
base=https://github.com/docker/machine/releases/tag/v0.16.0 &&
curl-L(uname -s)-$(uname -m)>/usr/local/bin/docker-machine &&
chmod+x /usr/local/bin/docker-machine
Install bash completion scripts
-
base=https://raw.githubusercontent.com/docker/machine/v0.16.0
fori indocker-machine-prompt.bash docker-machine-wrapper.bash docker-machine.bash
do
sudowget"{i}"-P/etc/bash_completion.d
doneTo enable thedocker-machine
shell prompt, add$(__docker_machine_ps1)
to yourPS1
setting in~/.bashrc
.
To enable the
docker-machine
shell prompt, add$(__docker_machine_ps1)
to yourPS1
setting in~/.bashrc
.
PS1='[\u@\h \W '
Get Start with Docker-Machine
Create a machine
List available machines
docker-machine ls
Create a Machine in VMwareFusion on MacOS
docker-machine create --driver vmwarefusion default
the name of Machine is default
Get the environment commands for Your new VM.
$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://172.16.62.130:2376"
export DOCKER_CERT_PATH="/Users//.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"Run this command to configure your shell:
eval "$(docker-machine env default)"
these information is used to set Env to connect to this docker machine
Set Env
This sets environment variables for the current shell that the Docker client reads which specify the TLS settings. You need to do this each time you open a new shell or restart your machine.
(docker-machine env default)" #defaut is vm's name
Unset Env**
Run eval $(docker-machine env -u)
to unset all DOCKER variables in the current shell.
Start and Stop machines
docker-machinestartdefault
Use Docker-Machine to provision hosts on cloud providers
- Amazon Web Services
$ docker-machine create --driver amazonec2 --amazonec2-access-key AKI******* --amazonec2-secret-key 8T93C******* aws-sandbox
- Generic Linux Hosts
$ docker-machinecreate
--drivergeneric
--generic-ip-address=203.0.113.81
--generic-ssh-key~/.ssh/id_rsa
vm #vm is the machine's name
- VMware Fusion
$ docker-machinecreate --drivervmwarefusion vm
--vmwarefusion-boot2docker-url
: URL for boot2docker image.
--vmwarefusion-cpu-count
: Number of CPUs for the machine (-1 to use the number of CPUs available)
--vmwarefusion-disk-size
: Size of disk for host VM (in MB).
--vmwarefusion-memory-size
: Size of memory for host VM (in MB).
--vmwarefusion-no-share
: Disable the mount of your home directory.
VMware vSphere
docker-machine create --driver vmwarevsphere --vmwarevsphere-username=user --vmwarevsphere-password=SECRET vm
Command Line
-
docker-machine active
See which machine is “active” (a machine is considered active if the
DOCKER_HOST
environment variable points to it). -
docker-machine config Name
print the connection config for machine
-
docker-machine inspect Name
print the info of the Machine by JSON format
-
docker-machine env {Name | -u}
display the ENV of the specified machine
display the Unset ENV info
-
docker-machine ip Name
get the machine's ip address
-
docker-machine url NAME
get the URL of the machine deamon
-
docker-machine kill NAME
Kill a machine
-
docker-machine ls
list machines
-
docker-machine restart NAME
restart a machine
-
docker-machine rm NAME
remove a machine
-
docker-machine ssh NAME
ssh to a machine
we can also use this command to excute a remote command:
docker-machine ssh NAME COMMAND
-
docker-machine scp A B
copy files between machines
-
docker-machine mount NAME:/home/Dir1 LocalDir1
mount the specified dir of the machine to local dir
--unmount, -u Unmount instead of mount
-
docker-machine start NAME
start a machine
-
docker-machine stop NAME
stop the machine
-
docker-machine status NAME
get the status of a machine
-
docker-machine upgrade NAME
Upgrade a machine to the latest version of Docker
-
docker-machine version
show the docker-machine version or a machine docker version