docker-machine

Docker Machine 则是一个安装和管理 Docker 的工具。它有自己的命令行工具:docker-machine。

安装

linux下安装docker-machine

首先下载二进制文件
wget https://github.com/docker/machine/releases/download/v0.13.0/docker-machine-Linux-x86_64

接着修改可执行权限
chmod +x docker-machine-Linux-x86_64

最后移动二进制文件到
/usr/local/bin/目录下 cp docker-machine-Linux-x86_64 /usr/local/bin/docker-machine
最后在命令行下测试下是不是可以使用了 docker
-machine -v

记住官网下https:
//docs.docker.com/machine/install-machine/#install-machine-directly

注意

[root@yanglin1 ~]# docker-machine create demo1         
Running pre-create checks...
Error with pre-create check: "VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path"
报错提示没有发现VBoxManage。因此,需要手工安装,具体安装操作如下。


[root@master ~]# vim  /etc/yum.repos.d/virtualbox.repo 
[virtualbox]
name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=0 repo_gpgcheck=0 gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc 

 

[root@master ~]# yum search VirtualBox   #查找具体安装版本
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirrors.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
============== N/S matched: VirtualBox ===================================
VirtualBox-4.3.x86_64 : Oracle VM VirtualBox
VirtualBox-5.0.x86_64 : Oracle VM VirtualBox VirtualBox-5.1.x86_64 : Oracle VM VirtualBox VirtualBox-5.2.x86_64 : Oracle VM VirtualBox
[root@master ~]# yum install -y VirtualBox-5.2  #安装

[root@master ~]# /sbin/vboxconfig   #重新加载virtualbox服务
vboxdrv.sh: Stopping 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-693.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-693.el7.x86_64 There were problems setting up VirtualBox. To re-start the set-up process, run /sbin/vboxconfig as root. #如果内核版本不一致,会出现上面的报错,需要安装相同的内核版本
 
   
[root@master ~]# rpm -ivh kernel-devel-3.10.0-693.el7.x86_64.rpm 
准备中...                          ################################# [100%] 正在升级/安装... 1:kernel-devel-3.10.0-693.el7 ################################# [100%] [root@slave1 ~]# yum install gcc make perl -y [root@slave1 ~]# rpm -qa kernel\* kernel-tools-3.10.0-693.el7.x86_64 kernel-devel-3.10.0-693.el7.x86_64 kernel-tools-libs-3.10.0-693.el7.x86_64 kernel-3.10.0-693.el7.x86_64 kernel-headers-3.10.0-862.3.2.el7.x86_64 [root@slave1 ~]# /sbin/vboxconfig vboxdrv.sh: Stopping VirtualBox services. vboxdrv.sh: Building VirtualBox kernel modules. vboxdrv.sh: Starting VirtualBox services. [root@centos7 ~]# docker-machine create --driver virtualbox testhost Running pre-create checks... Error with pre-create check: "This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory" #这个报错不用解释了吧,没有开启虚拟化功能,直接打开


root@centos7 ~]# docker-machine create --driver virtualbox default
Running pre-create checks...
(default) No default Boot2Docker ISO found locally, downloading the latest release...
(default) Latest release for github.com/boot2docker/boot2docker is v18.05.0-ce (default) Downloading /root/.docker/machine/cache/boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.05.0-ce/boot2docker.iso... (default) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100% Creating machine... (default) Copying /root/.docker/machine/cache/boot2docker.iso to /root/.docker/machine/machines/default/boot2docker.iso... (default) Creating VirtualBox VM... (default) Creating SSH key... (default) Starting the VM... (default) Check network to re-create if needed... (default) Found a new host-only adapter: "vboxnet0" (default) 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: docker-machine env default
#可以先安装个默认的虚拟机 [root@centos7 ~]# docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS default - virtualbox Running tcp://192.168.99.100:2376 v18.05.0-ce [root@centos7 ~]# docker-machine status Running

 

docker-machine命令

docker-machine active
显示当前的活动主机

docker-machine config
显示连接主机的配置

docker-machine create
创建一个主机

docker-machine env
设置当前的环境与哪个主机通信

docker-machine inspect
查看主机的详细信息

docker-machine ip
查看主机的IP 

docker-machine kill
强制关闭一个主机

docker-machine ls 
查看所有的主机信息

docker-machine provision
重新配置现在主机

docker-machine regenerate-certs
为主机重新生成证书

docker-machine restart
重启主机

docker-machine rm
删除主机

docker-machine ssh
以SSH的方式连接到主机上

docker-machine scp
远程复制

docker-machine status
查看主机的状态

docker-machine stop
停止一个正在运行的主机

docker-machine upgrade
升级主机的docker服务到最新版本

docker-machine version
查看docker-machine版本

案例




转载于:https://www.cnblogs.com/hbxZJ/p/10805895.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值