docker-machine(We support Virtualbox starting with version 5...)

博客主要讲述了docker-machine创建虚拟机时的报错问题及解决办法。运行/sbin/vboxconfig后提示安装kernel-devel,若再次执行仍提示安装,可能是内核版本不一致,可将内核升级或找到对应版本的kernel-devel安装,最后再次执行/sbin/vboxconfig启动虚拟机。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[root@tom docker-demo]# docker-machine create --driver virtualbox default
Running pre-create checks...
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
         available for the current kernel (3.10.0-957.21.3.el7.x86_64) or it failed to
        load. Please recompile the kernel module and install it by
           sudo /sbin/vboxconfig
         You will not be able to start VMs until this problem is fixed.
6.0.8r130520". Please upgrade at https://www.virtualbox.org"

docker-machine创建虚拟机时报错,提示运行/sbin/vboxconfig。

运行/sbin/vboxconfig

[root@tom docker-demo]# /sbin/vboxconfig 
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-957.21.3.el7.x86_64
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-957.21.3.el7.x86_64

There were problems setting up VirtualBox.  To re-start the set-up process, run
  /sbin/vboxconfig
as root.  If your system is using EFI Secure Boot you may need to sign the
kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load
them. Please see your Linux system's documentation for more information.

然后提示安装kernel-devel,输入y 一直等待执行完成

[root@tom docker-demo]# yum install kernel-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
....省略

再次 执行 /sbin/vboxconfig,如下则正常:

[root@tom docker-demo]# /sbin/vboxconfig 
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.

如果还是提示安装kernel-devel,可能是由于uname -r的内核版本和安装的内核版本不一致导致的,

[root@tom demo04compose]# uname -r
3.10.0-693.21.1.el7.x86_64
[root@tom demo04compose]# ll /usr/src/kernels/
total 4
drwxr-xr-x 22 root root 4096 Jun 21 17:14 3.10.0-957.21.3.el7.x86_64
[root@tom demo04compose]# 

此时有两个方法,一个是将内核升级到安装的内核版本,参照: 我是参照

另一个是找到内核对应版本的kernel-devel安装,卸载原有版本。

只有再次执行/sbin/vboxconfig启动虚拟机

 

<think>好的,用户遇到了一个错误,执行命令docker-machine create时提示命令未找到。我需要先分析可能的原因。首先,用户可能没有安装docker-machine工具。Docker Machine是一个独立的工具,需要单独安装,特别是如果他们在使用较旧的Docker版本或者Docker Toolbox的话。另外,用户可能安装的是Docker Desktop,而它可能没有包含docker-machine,或者路径没有正确配置。 接下来,我需要考虑不同的操作系统情况。用户使用的是VirtualBox驱动,可能是在Linux系统上,比如CentOS,因为提示符是[root@localhost ~]#。不过,Docker Machine在Linux上的安装方式可能与其他系统不同,需要确认正确的安装步骤。 可能的解决方案包括安装Docker Machine,或者如果用户已经安装了Docker Desktop,可能需要使用其他命令,比如docker swarm init来创建Swarm集群,而无需Docker Machine。同时,用户可能混淆了不同的Docker工具,需要解释Docker Machine的作用以及替代方案。 需要分步骤引导用户检查是否安装了Docker Machine,如果没有,指导如何安装,并提供不同操作系统的安装方法。同时,提醒用户注意版本兼容性和安装后的路径配置。此外,建议用户考虑使用Docker Desktop内置的Swarm功能,可能更简便。 最后,确保回答清晰,结构合理,使用中文,避免技术术语过于复杂,让用户能够一步步解决问题。</think>你遇到的错误 `-bash: docker-machine: command not found` 表示系统无法找到 `docker-machine` 命令。以下是逐步分析和解决方案: --- ### **原因分析** 1. **未安装 Docker Machine** `docker-machine` 是一个独立工具,用于在虚拟环境(如 VirtualBox)中创建和管理 Docker 主机。Docker Desktop 默认不包含此工具,需手动安装。 2. **环境变量未配置** 如果已安装但命令仍不可用,可能是安装路径未添加到系统的 `PATH` 环境变量中。 --- ### **解决方案** #### **方法 1:安装 Docker Machine** 适用于需要通过 VirtualBox 创建 Swarm 节点的场景。 1. **下载 Docker Machine 二进制文件** 在 Linux/CentOS 中执行以下命令: ```bash # 下载最新版(替换版本号) curl -L https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-$(uname -s)-$(uname -m) > /usr/local/bin/docker-machine # 添加可执行权限 chmod +x /usr/local/bin/docker-machine ``` 2. **验证安装** ```bash docker-machine --version # 应输出类似:docker-machine version 0.16.2, build xxxxxxx ``` --- #### **方法 2:使用 Docker Desktop 内置 Swarm 功能(推荐)** 如果你使用的是较新的 Docker 版本(如 Docker Desktop),`docker-machine` 已逐渐被弃用,建议直接使用 Docker Swarm: 1. **初始化 Swarm 集群** ```bash docker swarm init ``` 2. **添加节点** 根据输出提示,在其他机器上运行 `docker swarm join` 命令加入集群。 --- #### **方法 3:检查安装路径** 如果已安装但命令仍不可用,手动检查路径: ```bash # 查找 docker-machine 位置 sudo find / -name docker-machine # 将路径添加到环境变量(假设路径为 /usr/local/bin) export PATH=$PATH:/usr/local/bin ``` --- ### **补充说明** - **Docker Machine 的用途**:用于在虚拟机或云平台中创建 Docker 主机(如 VirtualBox、AWS),适用于旧版本 Docker 或非桌面环境。 - **现代替代方案**:Docker Desktop 已集成 Swarm 功能,推荐直接使用 `docker swarm` 命令管理集群。 执行上述步骤后,再次运行 `docker-machine create -d virtualbox swarm-manager` 应可正常执行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值