Docker Machine
Introduction
Docker Machine is a tool that allows you to install Docker on a virtual host and manage the hosts using the docker-machine command.
Docker Machine can also manage all docker hosts centrally, for example by quickly installing docker on 100 servers.
Docker Machine managed virtual hosts can be onboard or from a cloud provider such as AliCloud, Tencent Cloud, AWS, or DigitalOcean.
Using the docker-machine command, you can start, check, stop, and restart managed hosts, as well as upgrade Docker clients and daemons, and configure Docker clients to communicate with your hosts.
Installation
You need to install Docker before you can install Docker Machine.
Docker Machine can be installed on a variety of platforms, including Linux, MacOS, and windows.
Linux installation commands
$ base=https://github.com/docker/machine/releases/download/v0.16.0 &&
curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&
sudo mv /tmp/docker-machine /usr/local/bin/docker-machine &&
chmod +x /usr/local/bin/docker-machine
macOS installation commands
$ base=https://github.com/docker/machine/releases/download/v0.16.0 &&
curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/usr/local/bin/docker-machine &&
chmod +x /usr/local/bin/docker-machine
Windows installation commands
If you are on a Windows platform, you can use Git BASH and enter the following command.
$ base=https://github.com/docker/machine/releases/download/v0.16.0 &&
mkdir -p "$HOME/bin" &&
curl -L $base/docker-machine-Windows-x86_64.exe > "$HOME/bin/docker-machine.exe" &&
chmod +x "$HOME/bin/docker-machine.exe"
To see if the installation was successful.
$ docker-machine version
docker-machine version 0.16.0, build 9371605
Note: Installation instructions are also available inside the changelog for each version: https://github.com/docker/machine/releases
Usage
This chapter introduces the use of docker-machine through virtualbox. Other cloud providers are basically the same. You can refer to each provider’s documentation for details.
1. List the available machines
You can see that only the default virtual machine is currently available here.
$ docker-machine ls
2. Create a machine
Create a machine named test.
$ docker-machine create --driver virtualbox test
–driver: Specifies the type of driver used to create the machine, in this case virtualbox.
3. check the ip of the machine
$ docker-machine ip test
4. Stop the machine
$ docker-machine stop test
5. Start the machine
$ docker-machine start test
6. Enter the machine
$ docker-machine ssh test
docker-machine command parameter description
- docker-machine active: View the currently active Docker hosts.
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL
dev - virtualbox Running tcp://192.168.99.103:2376
staging * digitalocean Running tcp://203.0.113.81:2376
$ echo $DOCKER_HOST
tcp://203.0.113.81:2376
$ docker-machine active
staging
-
config: View the connection information of the currently active Docker host.
-
create: Create a Docker host
-
env: show the environment variables needed to connect to a host
-
inspect: output the details of the specified Docker in json format
-
ip: Get the address of the specified Docker host
-
kill: directly kill the specified Docker host
-
ls: List all managed hosts
-
provision: reconfigure the specified hosts
-
regenerate-certs: regenerate TLS information for a host
-
restart: reboot the specified host
-
rm: Delete a Docker host and the corresponding virtual machine will be deleted as well
-
ssh: Connect to the host via SSH and execute the command
-
scp: Copy data remotely between Docker hosts and between Docker hosts and local hosts via scp
-
mount: Mount or unmount a directory from a computer using SSHFS
-
start: Start a specified Docker host, or if the object is a virtual machine, the virtual machine will be started
-
status: Get the status of the specified Docker host (including: Running, Paused, Saved, Stopped, Stopping, Starting, Error), etc.
-
stop: Stop a specified Docker host
-
upgrade: Update the Docker version of a specified host to the latest
-
url: Get the listening URL of the specified Docker host
-
version: Show the version of the Docker Machine or the host Docker version
-
help: Show help information