English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Docker Machine

简介

Docker Machine 是一种可以让您在虚拟主机上安装 Docker 的工具,并可以使用 docker-machine 命令来管理主机。

Docker Machine 也可以集中管理所有的 docker 主机,比如快速的给 100 台服务器安装上 docker。

Docker Machine 管理的虚拟主机可以是机上的,也可以是云供应商,如阿里云,腾讯云,AWS,或 DigitalOcean。

使用 docker-machine 命令,您可以启动,检查,停止和重新启动托管主机,也可以升级 Docker 客户端和守护程序,以及配置 Docker 客户端与您的主机进行通信。

安装

安装 Docker Machine 之前你需要先安装 Docker。

Docker Machine 可以在多种平台上安装使用,包括 Linux 、MacOS 以及 windows。

Linux 安装命令

$ 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 安装命令

$ 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 安装命令

如果你是 Windows 平台,可以使用 Git BASH,并输入以下命令:

$ 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"

Check if the installation is successful:

$ docker-machine version
docker-machine version 0.16.0, build 9371605

Usage

This chapter introduces docker using virtualbox-Usage of machine. The operations of other cloud service providers are basically consistent. For details, please refer to the guidance documents of each service provider.

1List available machines

Currently, there is only the default virtual machine here.

$ docker-machine ls

2Create machine

Create a machine named test

$ docker-machine create --driver virtualbox test
  • --driverSpecify the driver type used to create the machine, here is virtualbox.

3View the IP of the machine

$ docker-machine ip test

4Stop the machine

$ docker-machine stop test

5Start the machine

$ docker-machine start test

6Enter the machine

$ docker-machine ssh test

docker-Description of machine command parameters

  • docker-machine activeView 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
  • configView the connection information of the currently active Docker host

  • creatCreate a Docker host

  • envShow the environment variables required to connect to a host

  • inspectOutput the detailed information of the specified Docker in json format

  • ipGet the address of the specified Docker host

  • killKill the specified Docker host directly

  • lsList all management hosts

  • provisionReconfigure the specified host

  • regenerate-certs: Regenerate TLS information for a host

  • restart: Restart the specified host

  • rm: Delete a Docker host, the corresponding virtual machine will also be deleted

  • ssh: Connect to the host through SSH and execute commands

  • scp: Copy data remotely between Docker hosts and between Docker hosts and local hosts through scp

  • mount: Mount or unmount directories from the computer using SSHFS

  • start: Start a specified Docker host, if the object 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) and other information

  • 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