docker-machine安装与使用

文章目录

  • 安装
    • window安装
      • win10家庭版
    • linux安装
  • 卸载
    • linux
  • 使用
    • 创建docker主机
      • 使用远程已有虚拟机
      • 直接使用虚拟机api创建machine
  • 命令示例
    • 查看
    • 其他参考

安装

window安装

安装教程 https://www.runoob.com/docker/windows-docker-install.html

win7、win8、win10家庭版 使用 docker-toolbox 安装
下载地址:http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/

win10专业版安装 Toolbox 下载地址: https://www.docker.com/get-docker

win10家庭版

在这里插入图片描述
docker120和docker121 是docker-machine创建的docker环境
docker122为已有主机上已经安装的docker加入到docker-machine中
defalut 为win10家庭版默认运行的虚拟机docker主机

linux安装

官方教程 https://docs.docker.com/machine/install-machine/

卸载

linux

Remove the executable: rm $(which docker-machine)

rm $(which docker-machine)

删除1或多台机器
docker-machine rm

$ docker-machine rm --help
Usage: docker-machine rm [OPTIONS] [arg...]

删除所有docker machine
To remove all machines: docker-machine rm -f $(docker-machine ls -q) (you might need to use -force on Windows).

docker-machine rm -f $(docker-machine ls -q)

使用

创建docker主机

使用远程已有虚拟机

测试创建120

  1. 设置免密登录目标主机192.168.72.120,docker-machine已经生产相关ssh签名

    ssh-copy-id [email protected]

  2. 安装docker machine

安装时需要一些时间下载包

docker-machine create --driver generic --generic-ip-address=192.168.72.120 docker120

  1. 避免 docker-machine ls 被防火墙防御无法正常访问docker tcp端口
    方式一:关闭并停止防火墙,避免 docker-machine,这里我直接关闭防火墙
systemctl stop firewalld; systemctl disable firewalld

方式二:添加放行的docker 2376端口

直接使用虚拟机api创建machine

docker-machine命令
在virtualbox下虚拟机下安装docker-machine

$ docker-machine create --driver virtualbox --engine-registry-mirror https://1rqn7spi.mirror.aliyuncs.com dockerA1

创建成功例子如下:

$ docker-machine create --driver virtualbox --engine-registry-mirror https://1rqn7spi.mirror.aliyuncs.com dockerA1
Running pre-create checks...
Creating machine...
(dockerA1) Copying C:\Users\lenovo\.docker\machine\cache\boot2docker.iso to C:\Users\lenovo\.docker\machine\machines\dockerA1\boot2docker.iso...
(dockerA1) Creating VirtualBox VM...
(dockerA1) Creating SSH key...
(dockerA1) Starting the VM...
(dockerA1) Check network to re-create if needed...
(dockerA1) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(dockerA1) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:\Users\lenovo\bin\docker-machine.exe env dockerA1

lenovo@lanwp MINGW64 /c/Program Files/Docker Toolbox
$ docker-machine.exe ls
NAME        ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
default     *        virtualbox   Running   tcp://192.168.99.100:2376           v18.09.6
docker120   -        generic      Running   tcp://192.168.72.120:2376           v18.09.6
docker121   -        generic      Running   tcp://192.168.72.121:2376           v18.09.6
docker122   -        generic      Running   tcp://192.168.72.122:2376           Unknown    Unable to query docker version: Get https://192.168.72.122:2376/v1.15/version: dial tcp 192.168.72.122:2376: connectex: No connection could be made because the target machine actively refused it.
dockerA1    -        virtualbox   Running   tcp://192.168.99.101:2376           v18.09.6

lenovo@lanwp MINGW64 /c/Program Files/Docker Toolbox
$ docker-machine.exe ip dockerA1
192.168.99.101

docker122提示的信息时因为 主机中的docker为自己手动安装,为配置 tls 相关证书,不是使用docker-machine安装的(docker-machine安装已经配置好相关的 tls证书)

命令示例

查看

docker-machine ls

$ docker-machine ls
NAME        ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
default     *        virtualbox   Running   tcp://192.168.99.100:2376           v18.09.6
docker120   -        generic      Running   tcp://192.168.72.120:2376           v18.09.6
docker121   -        generic      Running   tcp://192.168.72.121:2376           v18.09.6
docker122   -        generic      Running   tcp://192.168.72.122:2376           Unknown    Unable to query docker version: Get https://192.168.72.122:2376/v1.15/version: dial tcp 192.168.72.122:2376: connectex: No connection could be made because the target machine actively refused it.
dockerA1    -        virtualbox   Running   tcp://192.168.99.101:2376           v18.09.6

查看docker-machine中docker主机名
docker-machine ls -q

$ docker-machine ls -q
default
docker120
docker121
docker122

配置
docker-machine config

$ docker-machine.exe config
--tlsverify
--tlscacert="C:\\Users\\lenovo\\.docker\\machine\\machines\\default\\ca.pem"
--tlscert="C:\\Users\\lenovo\\.docker\\machine\\machines\\default\\cert.pem"
--tlskey="C:\\Users\\lenovo\\.docker\\machine\\machines\\default\\key.pem"
-H=tcp://192.168.99.100:2376

环境变量
查看默认主机 default的环境变量 docker-machine.exe env
查看指定主机 docker120的环境变量 docker-machine.exe env docker120

lenovo@lanwp MINGW64 /c/Program Files/Docker Toolbox
$ docker-machine.exe env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="C:\Users\lenovo\.docker\machine\machines\default"
export DOCKER_MACHINE_NAME="default"
export COMPOSE_CONVERT_WINDOWS_PATHS="true"
# Run this command to configure your shell:
# eval $("C:\Users\lenovo\bin\docker-machine.exe" env)

lenovo@lanwp MINGW64 /c/Program Files/Docker Toolbox
$ docker-machine.exe env docker120
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.72.120:2376"
export DOCKER_CERT_PATH="C:\Users\lenovo\.docker\machine\machines\docker120"
export DOCKER_MACHINE_NAME="docker120"
export COMPOSE_CONVERT_WINDOWS_PATHS="true"
# Run this command to configure your shell:
# eval $("C:\Users\lenovo\bin\docker-machine.exe" env docker120)

查看IP
docker-machine.exe ip 默认查看default主机的IP

$ docker-machine.exe ip
192.168.99.100

lenovo@lanwp MINGW64 /c/Program Files/Docker Toolbox
$ docker-machine.exe ip docker120
192.168.72.120

其他参考

$ docker-machine.exe
Usage: docker-machine.exe [OPTIONS] COMMAND [arg...]

Create and manage machines running Docker.

Version: 0.16.0, build 702c267f

Author:
  Docker Machine Contributors - 

Options:
  --debug, -D                                           Enable debug mode
  --storage-path, -s "C:\Users\lenovo\.docker\machine"  Configures storage path [$MACHINE_STORAGE_PATH]
  --tls-ca-cert                                         CA to verify remotes against [$MACHINE_TLS_CA_CERT]
  --tls-ca-key                                          Private key to generate certificates [$MACHINE_TLS_CA_KEY]
  --tls-client-cert                                     Client cert to use for TLS [$MACHINE_TLS_CLIENT_CERT]
  --tls-client-key                                      Private key used in client TLS auth [$MACHINE_TLS_CLIENT_KEY]
  --github-api-token                                    Token to use for requests to the Github API [$MACHINE_GITHUB_API_TOKEN]
  --native-ssh                                          Use the native (Go-based) SSH implementation. [$MACHINE_NATIVE_SSH]
  --bugsnag-api-token                                   BugSnag API token for crash reporting [$MACHINE_BUGSNAG_API_TOKEN]
  --help, -h                                            show help
  --version, -v                                         print the version

Commands:
  active                Print which machine is active
  config                Print the connection config for machine
  create                Create a machine
  env                   Display the commands to set up the environment for the Docker client
  inspect               Inspect information about a machine
  ip                    Get the IP address of a machine
  kill                  Kill a machine
  ls                    List machines
  provision             Re-provision existing machines
  regenerate-certs      Regenerate TLS Certificates for a machine
  restart               Restart a machine
  rm                    Remove a machine
  ssh                   Log into or run a command on a machine with SSH.
  scp                   Copy files between machines
  mount                 Mount or unmount a directory from a machine with SSHFS.
  start                 Start a machine
  status                Get the status of a machine
  stop                  Stop a machine
  upgrade               Upgrade a machine to the latest version of Docker
  url                   Get the URL of a machine
  version               Show the Docker Machine version or a machine docker version
  help                  Shows a list of commands or help for one command

Run 'docker-machine.exe COMMAND --help' for more information on a command.

你可能感兴趣的:(linux,docker)