Docker machine

Time:2021-1-11

brief introduction

Docker machine is a tool that allows you to install docker on a virtual host and use the docker machine command to manage the host.

Docker machine can also centrally manage all docker hosts, such as quickly installing dockers on 100 servers.
The virtual host managed by docker machine can be on-board or cloud provider, such as alicloud, Tencent cloud, AWS or digital ocean.

With the docker machine command, you can start, check, stop and restart the managed host, upgrade the docker client and daemons, and configure the docker client to communicate with your host.

install

You need to install docker before installing docker machine.

Docker mechine can be installed on a variety of 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

Mac OS 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 setup command

If you are a Windows platform, you can useGit 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 whether the installation is successful:

$ docker-machine version

use

This chapter introduces how to use docker machine through VirtualBox. The operation of other cloud service providers is basically consistent with this. For details, please refer to the guidance documents of each service provider.

1. List available machines

You can see that there is only default virtual machine here.

$ docker-machine ls

2. Creating machines

Create a machine called test.

$ docker-machine create --driver virtualbox test
  • –driver: Specifies the type of driver used to create the machine, here is the VirtualBox.

3. View the IP address 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

Parameter description of docker machine command

$ 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
  • docker-machine active: view the currently activated docker host.

  • config: view the connection information of the currently activated docker host.

  • creat: create docker host

  • env: displays the environment variables needed to connect to a host

  • inspect: output the details of the specified docker in JSON format

  • ip: gets the address of the specified docker host

  • kill: directly kill the specified docker host

  • ls: list all management hosts

  • provision: reconfigure the specified host

  • regenerate-certs: regenerate TLS information for a host

  • restart: restart the specified host

  • rm: delete a docker host, and the corresponding virtual machine will also be deleted

  • ssh: connect to the host through SSH and execute the command

  • scp: remote data replication between docker hosts and between docker hosts and local hosts through SCP

  • mount: use sshfs to load or unload a directory from a computer

  • start: start a specified docker host. 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: stops a specified docker host

  • upgrade: update the docker version of a specified host to the latest version

  • url: get the listening URL of the specified docker host

  • version: displays the version of docker machine or the host docker version

  • help: display help information

Link to the original text:www.runoob.com/docker/docker-machi…

This work adoptsCC agreementReprint must indicate the author and the link of this article