背景说明

Docker Machine是一个集中管理Docker主机的工具,本地的Docker Client所指向的Docker Machine同时只能和一个远程的Docker Machine进行通信。

解决方案

激活主机

  1. [root@vm1 ~]# docker-machine ls
  2. NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
  3. deephash-master - virtualbox Running tcp://192.168.99.101:2376 v19.03.12
  4. hostvm - virtualbox Stopped Unknown
  5. manage - virtualbox Stopped Unknown
  6. [root@vm1 ~]# docker-machine env deephash-master
  7. export DOCKER_TLS_VERIFY="1"
  8. export DOCKER_HOST="tcp://192.168.99.101:2376"
  9. export DOCKER_CERT_PATH="/root/.docker/machine/machines/deephash-master"
  10. export DOCKER_MACHINE_NAME="deephash-master"
  11. # Run this command to configure your shell:
  12. # eval $(docker-machine env deephash-master)
  13. [root@vm1 ~]# eval $(docker-machine env deephash-master)
  14. [root@vm1 ~]#
  15. [root@vm1 ~]# docker-machine active
  16. deephash-master
  17. [root@vm1 ~]#

active命令打印当前docker客户端和哪个docker machine进行通信

主机配置

打印当前docker machine的配置信息

  1. [root@vm1 ~]# docker-machine config deephash-master
  2. --tlsverify
  3. --tlscacert="/root/.docker/machine/machines/deephash-master/ca.pem"
  4. --tlscert="/root/.docker/machine/machines/deephash-master/cert.pem"
  5. --tlskey="/root/.docker/machine/machines/deephash-master/key.pem"
  6. -H=tcp://192.168.99.101:2376
  7. [root@vm1 ~]#

主机状态

  1. [root@vm1 ~]# docker-machine status
  2. Error: No machine name(s) specified and no "default" machine exists
  3. [root@vm1 ~]# docker-machine create default
  4. Running pre-create checks...
  5. Creating machine...
  6. (default) Copying /root/.docker/machine/cache/boot2docker.iso to /root/.docker/machine/machines/default/boot2docker.iso...
  7. (default) Creating VirtualBox VM...
  8. (default) Creating SSH key...
  9. (default) Starting the VM...
  10. (default) Check network to re-create if needed...
  11. (default) Waiting for an IP...
  12. Waiting for machine to be running, this may take a few minutes...
  13. Detecting operating system of created instance...
  14. Waiting for SSH to be available...
  15. Detecting the provisioner...
  16. Provisioning with boot2docker...
  17. Copying certs to the local machine directory...
  18. Copying certs to the remote machine...
  19. Setting Docker configuration on the remote daemon...
  20. Checking connection to Docker...
  21. Docker is up and running!
  22. To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env default
  23. [root@vm1 ~]# docker-machine ls
  24. NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
  25. deephash-master * virtualbox Running tcp://192.168.99.101:2376 v19.03.12
  26. default - virtualbox Running tcp://192.168.99.103:2376 v19.03.12
  27. hostvm - virtualbox Stopped Unknown
  28. manage - virtualbox Stopped Unknown
  29. [root@vm1 ~]#
  30. [root@vm1 ~]# docker-machine status
  31. Running
  32. [root@vm1 ~]#