1、使用Docker Machine可以高效地管理多个host主机,可以批量安装和配置docker host,这个host可以使本地的虚拟机、物理机,也可以是公有云中的云主机。
2、Docker Machine将一部分host划分为一个环境(provider),对于某个特定的provider,Docker Machine使用相对应的driver安装和配置docker host
Docker Machine 安装
[root@localhost ~]# base=https://github.com/docker/machine/releases/download/v0.16.0 && curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine && sudo install /tmp/docker-machine /usr/local/bin/docker-machine
如果出现错误
curl: (7) Failed connect to github-production-release-asset-2e65be.s3.amazonaws.com:443; Connection refused
执行 echo "219.76.4.4 github-cloud.s3.amazonaws.com" >> /etc/hosts
[root@localhost ~]# docker-machine --version
[root@localhost ~]# vim /usr/local/etc/bash_completion.d
base=https://raw.githubusercontent.com/docker/machine/v0.16.0
for i in docker-machine-prompt.bash docker-machine-wrapper.bash docker-machine.bash
do
sudo wget "$base/contrib/completion/bash/${i}" -P /etc/bash_completion.d
done
[root@localhost ~]# source /usr/local/etc/bash_completion.d
[root@localhost ~]# source /etc/bash_completion.d/docker-machine-prompt.bash
[root@localhost ~]# vim /root/.bashrc
PS1='[\u@\h \W$(__docker_machine_ps1)]\$ '
[root@localhost ~]# source /root/.bashrc
Docker Machine 创建
此处每个客户机清除防火墙规则 iptables -F并且iptables-save
[root@localhost ~]# ssh-keygen -t rsa 连续回车三次
[root@localhost ~]# ssh-copy-id -i root@被管理host的IP
[root@localhost ~]# docker-machine create --driver generic --generic-ip-address 192.168.52.131 --generic-ssh-key /root/.ssh/id_rsa --generic-ssh-user root host1
Docker Machine 管理
[root@localhost ~]# docker-machine ls 查看当前加入管理的host主机
[root@localhost ~]# docker-machine env host1 查看host1配置详情
[root@localhost ~]# eval $(docker-machine env host1) 使用当前shell输出内容交由host1处理
[root@localhost ~]# docker-machine ssh host1 登录到host1
Docker 加速器配置
https://www.daocloud.io/mirror
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
该脚本可以将 --registry-mirror 加入到你的 Docker 配置文件 /etc/docker/daemon.json 中。适用于 Ubuntu14.04、Debian、CentOS6 、CentOS7、Fedora、Arch Linux、openSUSE Leap 42.1,其他版本可能有细微不同。更多详情请访问文档。