Docker Machine
Introduction
Docker Machine is a tool that allows you to install Docker on virtual hosts and manage them with the docker-machine command.
Docker Machine can also centrally manage all Docker hosts, such as quickly installing Docker on 100 servers.
The virtual hosts managed by Docker Machine can be local or cloud providers like Alibaba Cloud, Tencent Cloud, AWS, or DigitalOcean.
Using the docker-machine command, you can start, inspect, stop, and restart managed hosts, upgrade the Docker client and daemon, and configure the Docker client to communicate with your hosts.
Installation
Before installing Docker Machine, you need to install Docker.
Docker Machine can be installed on various platforms, including Linux, MacOS, and Windows.
Linux Installation Command
$ 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 Command
$ 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 Command
If you are on Windows, 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 check if the installation was successful:
$ docker-machine version
docker-machine version 0.16.0, build 9371605
Note: The installation instructions can also be found in the release notes for each version: https://github.com/docker/machine/releases
Usage
This chapter introduces the usage of docker-machine through virtualbox. The operations for other cloud service providers are generally consistent. Refer to the specific documentation of each service provider for details.
1. List Available Machines
You can see that only the default virtual machine is available here.
$ docker-machine ls
2. Create a Machine
Create a machine named "test".
$ docker-machine create --driver virtualbox test
--driver: Specifies the driver type used to create the machine, in this case, virtualbox.
3. View Machine IP
$ docker-machine ip test
4. Stop a Machine
$ docker-machine stop test
5. Start a Machine
$ docker-machine start test
6. Access a Machine
$ docker-machine ssh test
docker-machine Command Parameters
docker-machine active: View the currently active Docker host.
$ 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 connection information for the current active Docker host.
- create: Create a Docker host.
- env: Display environment variables required to connect to a host.
- inspect: Output detailed information of a specified Docker host in JSON format.
- ip: Get the address of a specified Docker host.
- kill: Kill a specified Docker host directly.
- ls: List all managed hosts.
- provision: Reconfigure a specified host.
- regenerate-certs: Regenerate TLS information for a specified host.
- restart: Restart a specified host.
- rm: Delete a specified Docker host, and the corresponding virtual machine will also be deleted.
- ssh: Connect to a host via SSH and execute commands.
- scp: Copy data remotely between Docker hosts and the local host.
- mount: Mount or unmount directories using SSHFS from the computer.
- start: Start a specified Docker host; if it is a virtual machine, the virtual machine will be started.
- status: Get the status of a specified Docker host (including: Running, Paused, Saved, Stopped, Stopping, Starting, Error).
- stop: Stop a specified Docker host.
- upgrade: Update the Docker version of a specified host to the latest.
- url: Get the listening URL of a specified Docker host.
- version: Display the version of Docker Machine or the host Docker version.
- help: Display help information.