Docker Machine 安装使用教程
Docker Machine 安装教程
这里演示两台服务 A和B
A为主服务器 B为从服务器
下面1,2步为A主服务器安装
最新发布版本: https://github.com/docker/machine/releases
1.安装脚本
base=https://github.com/docker/machine/releases/download/v0.16.2 &&
curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&
sudo mv /tmp/docker-machine /usr/local/bin/docker-machine &&
chmod +x /usr/local/bin/docker-machine
如果遇到:
sudo: 在加载插件“sudoers_policy”时在 /etc/sudo.conf 第 19 行出错 sudo: /usr/libexec/sudo/sudoers.so 必须属于用户 ID 0(的用户) sudo: 致命错误,无法加载插件
需要设置一下权限:
chown root:root /usr/
chown root:root /usr/libexec/sudo/sudoers.so
chown root:root /etc/
2. 查看是否安装成功
docker-machine version
3.离线安装
版本: 0.16.2
迅雷云链接:https://pan.xunlei.com/s/VMNTiyMYmR2TiOb0i50S7MbGA1
提取码:h4tx
# 1.将下载文件移动到/usr/local/bin/docker-machine
mv docker-machine-Linux-x86_64 /usr/local/bin/docker-machine
# 2.执行权限
chmod +x /usr/local/bin/docker-machine
# 3.验证
docker-machine -v
4.使用
4.1 先设置服务器免密登录
参考链接:https://blog.csdn.net/WeiHao0240/article/details/110239187
4.2 创建 machine
docker-machine create -d generic \
--generic-ip-address=192.168.48.132 \
--generic-ssh-key ~/.ssh/id_rsa \
m2
docker-machine create
创建语句--driver
选择的driver--generic-ip-address
需要连接的目标主机IP--generic-ssh-key
免密证书
m1 你取machine名称
然后会出现以下代码, 请耐心等待, 不要退出…
Creating CA: /root/.docker/machine/certs/ca.pem
Creating client certificate: /root/.docker/machine/certs/cert.pem
Running pre-create checks...
Creating machine...
(m1) Importing SSH key...
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 centos...
4.3 报错
创建时出错:检查主机时出错:检查或重新生成证书:验证主机“192.168.88.131:2376”的证书时出错:tcp 192.168.88.131:2376:连接:没有到主机的路由
#您可以尝试使用“docker machine regenerate certs[name]”重新生成它们。
#请注意,这将触发Docker后台程序重新启动,这可能会停止运行容器。
Error creating machine: Error checking the host: Error checking and/or regenerating the certs: There was an error validating certificates for host “192.168.88.130:2376”: dial tcp 192.168.88.130:2376: connect: no route to host
You can attempt to regenerate them using ‘docker-machine regenerate-certs [name]’.
Be advised that this will trigger a Docker daemon restart which might stop running containers.
Unknown Unable to query docker version: Get https://192.168.88.130:2376/v1.15/version:remote error: tls: bad certificate
# 解决方法:
# 1.按提示重新生成
docker-machine regenerate-certs m1
# 2.重启一下那个机器, 这时m1机器会重启!
docker-machine restart m1
# 3.需要手动启动一下
docker-machine start m1
# 4.查看机器列表
docker-machine ls
connect: no route to host
# 此时目标主机docker已经安装好, 但需要关闭目标防火墙, 或者开启2376端口
# 1:查看防火状态
systemctl status firewalld
# 2:暂时关闭防火墙
systemctl stop firewalld
# 3:永久关闭防火墙
systemctl disable firewalld
# 4:重启防火墙
systemctl enable firewalld