CentOS 7.6.1810 安装 Docker-machine 0.16.0
其它系统安装说明请访问:官方文档
Centos 7系统请使用如下代码:
$ base=https://github.com/docker/machine/releases/download/v0.16.0 && curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&
chmod +x /tmp/docker-machine && sudo install /tmp/docker-machine /usr/bin/docker-machine
Check the installation by displaying the Machine version:
$ docker-machine version docker-machine version 0.16.0, build 9371605
下载 completion script:docker-machine-prompt.bash docker-machine-wrapper.bash docker-machine.bash 将其放在/etc/bash_completion.d目录下
bash文件下载地址
编辑 /root/.bashrc文件如下
vim /root/.bashrc
PS1='[\u@\h \W$(__docker_machine_ps1)]\$ '
若出现如下错误
请在 /root/.bashrc 添加如下代码
source /etc/bash_completion.d/docker-machine-wrapper.bash source /etc/bash_completion.d/docker-machine-prompt.bash source /etc/bash_completion.d/docker-machine.bash
并重新source下bashrc
source /root/.bashrc
安装完成。
通过docker-machine在其它host创建docker,创建 machine 要求能够无密码登录远程主机,所以需要先通过如下命令将 ssh key 拷贝到 192.168.1.206. 可查 官方文档
ssh-keygen #生成密钥,生成位置/root/.ssh/
ssh-copy-id [email protected] #复制公钥至远程目标
ssh 192.168.1.206 #远程目标
vim /etc/ssh/sshd.config #配置远程主机
PubkeyAuthentication yes #打开此行注释
service sshd restart #重启ssh服务
setenfoce 0 #官方并没有提示关闭远程主机的selinux,但是我关闭了
systemctl stop firewalld #关闭远程主机的防火墙
systemctl disable firewalld #禁止开机启动
一切准备就绪,执行 docker-machine create
命令创建 docker(此处为计算机名,可以是elk,zabbix,mysql等有意义的名字)
docker-machine create -d generic --generic-ip-address=192.168.1.234 --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user=root docker #虚机使用此行
# docker-machine create --driver generic --generic-ip-address=192.168.1.206 elk #cloudman ubuntu16.0.4使用
执行 docker-machine ls查看安装完成的docker
docker-machine ls
远程到目标主机并查看docker daemon 的具体配置
vim /etc/systemd/system/docker.service.d/10-machine.conf #针对centos 7.6.1810
# vim /etc/systemd/system/docker.service #针对ubuntu 16.0.4
-
-H tcp://0.0.0.0:2376
使 docker daemon 接受远程连接。 -
--tls*
对远程连接启用安全认证和加密。
查看远程主机docker的env环境
docker-machine env docker
eval $(docker-machine env docker) #通过docker-machine管理192.168.1.234上的docker
看到命令行提示符已经变了,其原因是我们之前在$HOME/.bashrc
中配置了 PS1='[\u@\h \W$(__docker_machine_ps1)]\$ '
,用于显示当前 docker host。
eval $(docker-machine env zabbix) #切换到 zabbix
docker-machine upgrade docker zabbix #批量执行更新 machine 的 docker 到最新版本
docker-machine config docker #查看machine 的 docker daemon 配置
stop/start/restart
是对 machine 的操作系统操作,而 不是 stop/start/restart docker daemon
docker-machine scp docker:/tmp/a zabbix:/tmp/b #在不同的host之间拷贝数据
以上是通过docker-machine远程其它主机安装docker,及一些常用操作
下面是如何通过docker-machinet删除之前安装docker. 官网文档
Remove a machine. This removes the local reference and deletes it on the cloud provider or virtualization management platform.
$ docker-machine rm --help Usage: docker-machine rm [OPTIONS] [arg...] Remove a machine Description: Argument(s) are one or more machine names. Options: --force, -f Remove local configuration even if machine cannot be removed, also implies an automatic yes (`-y`) -y Assumes automatic yes to proceed with remove, without prompting further user confirmation
Examples
$ docker-machine ls NAME ACTIVE URL STATE URL SWARM DOCKER ERRORS bar - virtualbox Running tcp://192.168.99.101:2376 v1.9.1 baz - virtualbox Running tcp://192.168.99.103:2376 v1.9.1 foo - virtualbox Running tcp://192.168.99.100:2376 v1.9.1 qix - virtualbox Running tcp://192.168.99.102:2376 v1.9.1 $ docker-machine rm baz About to remove baz Are you sure? (y/n): y Successfully removed baz $ docker-machine ls NAME ACTIVE URL STATE URL SWARM DOCKER ERRORS bar - virtualbox Running tcp://192.168.99.101:2376 v1.9.1 foo - virtualbox Running tcp://192.168.99.100:2376 v1.9.1 qix - virtualbox Running tcp://192.168.99.102:2376 v1.9.1 $ docker-machine rm bar qix About to remove bar, qix Are you sure? (y/n): y Successfully removed bar Successfully removed qix $ docker-machine ls NAME ACTIVE URL STATE URL SWARM DOCKER ERRORS foo - virtualbox Running tcp://192.168.99.100:2376 v1.9.1 $ docker-machine rm -y foo About to remove foo Successfully removed foo