背景说明

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

解决方案

文件下载

  1. [root@vm1 ~]# curl -L https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine
  2. [root@vm1 ~]# chmod +x /tmp/docker-machine
  3. [root@vm1 ~]# sudo cp /tmp/docker-machine /usr/local/bin/docker-machine

版本查看

  1. [root@vm1 ~]# docker-machine version
  2. docker-machine version 0.16.2, build bd45ab13
  3. [root@vm1 ~]#

驱动安装

尝试执行主机创建命令,发现缺失驱动VBoxManage

  1. [root@vm1 ~]# docker-machine create --driver virtualbox myvm1
  2. Running pre-create checks...
  3. Error with pre-create check: "VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path"
  4. [root@vm1 ~]# yum install virtualbox
  5. Loaded plugins: fastestmirror
  6. Loading mirror speeds from cached hostfile
  7. * base: mirrors.aliyun.com
  8. * epel: mirrors.bfsu.edu.cn
  9. * extras: mirrors.aliyun.com
  10. * updates: mirrors.aliyun.com
  11. No package virtualbox available.
  12. Error: Nothing to do

创建仓库Repo文件/etc/yum.repos.d/virtualbox.repo

  1. [root@vm1 ~]# cd /etc/yum.repos.d/
  2. [root@vm1 yum.repos.d]# touch virtualbox.repo
  3. [root@vm1 yum.repos.d]# vim virtualbox.repo

文件内容如下

  1. [virtualbox]
  2. name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
  3. baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
  4. enabled=1
  5. gpgcheck=1
  6. repo_gpgcheck=1
  7. gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc

也可以通过命令直接下载: wget http://downlo[ad](https://dfm.elecfans.com/uploads/software/hqdfm.zip?neilian).virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo

执行仓库更新

  1. [root@vm1 yum.repos.d]# yum clean all
  2. Loaded plugins: fastestmirror
  3. Cleaning repos: base docker-ce-stable epel extras updates virtualbox
  4. Cleaning up list of fastest mirrors
  5. [root@vm1 yum.repos.d]# yum makecache
  6. Loaded plugins: fastestmirror

安装驱动

  1. [root@vm1 yum.repos.d]# yum install -y VirtualBox-5.1

此时执行创建发现仍然出现错误

  1. [root@vm1 yum.repos.d]# docker-machine create -d virtualbox manager
  2. Running pre-create checks...
  3. Error with pre-create check: "We support Virtualbox starting with version 5. Your VirtualBox install is \"WARNING: The vboxdrv kernel module is not loaded. Either there is no module\\n available for the current kernel (3.10.0-957.el7.x86_64) or it failed to\\n load. Please recompile the kernel module and install it by\\n\\n sudo /sbin/vboxconfig\\n\\n You will not be able to start VMs until this problem is fixed.\\n5.1.38r122592\". Please upgrade at https://www.virtualbox.org"

执行/sbin/vboxconfig检查virtualbox安装配置

  1. [root@vm1 yum.repos.d]# /sbin/vboxconfig
  2. vboxdrv.sh: Stopping VirtualBox services.
  3. vboxdrv.sh: Building VirtualBox kernel modules.
  4. This system is not currently set up to build kernel modules (system extensions).
  5. Running the following commands should set the system up correctly:
  6. yum install gcc make
  7. yum install kernel-devel-3.10.0-957.el7.x86_64
  8. (The last command may fail if your system is not fully updated.)
  9. yum install kernel-devel
  10. vboxdrv.sh: failed: Look at /var/log/vbox-install.log to find out what went wrong.
  11. This system is not currently set up to build kernel modules (system extensions).
  12. Running the following commands should set the system up correctly:
  13. yum install gcc make
  14. yum install kernel-devel-3.10.0-957.el7.x86_64
  15. (The last command may fail if your system is not fully updated.)
  16. yum install kernel-devel
  17. There were problems setting up VirtualBox. To re-start the set-up process, run
  18. /sbin/vboxconfig
  19. as root.

按照如上命令进行安装https://mirror.nsc.liu.se/centos-store/7.6.1810/isos/x86_64/目录下的CentOS-7-x86_64-DVD-1810.iso
image.png

  1. [root@vm1 yum.repos.d]# yum install -y gcc make
  2. [root@vm1 ~]# rpm -ivh kernel-devel-3.10.0-957.el7.x86_64.rpm

再次执行创建命令,仍然报错

  1. [root@vm1 ~]# docker-machine create -d virtualbox manage
  2. Running pre-create checks...
  3. Error with pre-create check: "We support Virtualbox starting with version 5. Your VirtualBox install is \"WARNING: The vboxdrv kernel module is not loaded. Either there is no module\\n available for the current kernel (3.10.0-957.el7.x86_64) or it failed to\\n load. Please recompile the kernel module and install it by\\n\\n sudo /sbin/vboxconfig\\n\\n You will not be able to start VMs until this problem is fixed.\\n5.1.38r122592\". Please upgrade at https://www.virtualbox.org"

再次执行命令/sbin/vboxconfig

  1. [root@vm1 ~]# /sbin/vboxconfig
  2. vboxdrv.sh: Stopping VirtualBox services.
  3. vboxdrv.sh: Building VirtualBox kernel modules.
  4. vboxdrv.sh: Starting VirtualBox services.

再次执行创建命令,仍然报错

  1. [root@vm1 ~]# docker-machine create -d virtualbox manage
  2. Running pre-create checks...
  3. Error with pre-create check: "This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory"
  4. [root@vm1 ~]#

关闭虚拟机,并调整虚拟机配置
image.png
再次开启机器
image.pngimage.png
image.png
image.png
image.png
image.png
image.png
彻底关闭 Hyper-V 服务
image.png
右键开始图标打开“Windows PowerShell (管理员)(A)”
在 Windows PowerShell 执行命令:bcdedit /set hypervisorlaunchtype off

部署验证

此时再次创建,正常执行

  1. [root@vm1 ~]# docker-machine create -d virtualbox manage
  2. Running pre-create checks...
  3. Creating machine...
  4. (manage) Copying /root/.docker/machine/cache/boot2docker.iso to /root/.docker/machine/machines/manage/boot2docker.iso...
  5. (manage) Creating VirtualBox VM...
  6. (manage) Creating SSH key...
  7. (manage) Starting the VM...
  8. (manage) Check network to re-create if needed...
  9. (manage) Found a new host-only adapter: "vboxnet0"
  10. (manage) Waiting for an IP...

查看主机和版本

  1. [root@vm1 ~]# docker-machine ls
  2. NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
  3. manage - virtualbox Running tcp://192.168.99.100:2376 v19.03.12
  4. [root@vm1 ~]#
  5. [root@vm1 ~]# docker-machine ssh manage
  6. ( '>')
  7. /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY.
  8. (/-_--_-\) www.tinycorelinux.net
  9. docker@manage:~$ docker version
  10. Client: Docker Engine - Community
  11. Version: 19.03.12
  12. API version: 1.40
  13. Go version: go1.13.10
  14. Git commit: 48a66213fe
  15. Built: Mon Jun 22 15:42:53 2020
  16. OS/Arch: linux/amd64
  17. Experimental: false
  18. Server: Docker Engine - Community
  19. Engine:
  20. Version: 19.03.12
  21. API version: 1.40 (minimum version 1.12)
  22. Go version: go1.13.10
  23. Git commit: 48a66213fe
  24. Built: Mon Jun 22 15:49:35 2020
  25. OS/Arch: linux/amd64
  26. Experimental: false
  27. containerd:
  28. Version: v1.2.13
  29. GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
  30. runc:
  31. Version: 1.0.0-rc10
  32. GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
  33. docker-init:
  34. Version: 0.18.0
  35. GitCommit: fec3683
  36. docker@manage:~$

[

](https://www.bilibili.com/video/BV1wQ4y1Y7SE?p=31)