docker machine

注意:

如果是虚拟机网络一定要确保是:
桥接模式
桥接模式
桥接模式
重要的话说三遍

实验环境:

首先开三台Centos7

IP:192.168.43.111
IP:192.168.43.222
IP:192.168.1.233

然后在第一台IP:192.168.43.111的虚拟机上安装docker machine

关闭防火墙

实验步骤:

1. 安装docker machine

首先去docker官网:https://docs.docker.com/machine/install-machine/
找到linux版本的二进制脚本

复制下面的代码粘贴到centos7命令行执行(不知道为什么有的时候这里只有网卡在net模式才可以正常下载)然后可以等待下载完成切换回桥接模式再安装docker

[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

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    134      0 --:--:--  0:00:04 --:--:--   134
  7 26.8M    7 2175k    0     0   2214      0  3:32:01  0:16:46  3:15:15     0
不着急,慢慢等...        一年后...mmp,怎么还没好???

然后往下再找到对应的bash脚本

创建一个bash脚本并写入这段代码

vim /etc/bash_completion.d/docker-machine-prompt.bash

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

然后执行这个bash脚本

[root@localhost ~]# source /etc/bash_completion.d/docker-machine-prompt.bash

2. 配置SSH

允许root用户登录SSH(其他两台机器的SSH服务也要做相同配置)

[root@localhost ~]# vim /etc/ssh/sshd_config

重启SSH服务

[root@localhost ~]# systemctl restart sshd

实现免密登录(一路Enter即可)

[root@localhost ~]# ssh-keygen 

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:zotZ6OvUO6HRkmS8y0NJeZPLmzH/z3Kr3M8KYEQ1jiQ root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|        E o.o    |
|         + o .   |
|     . . .o .    |
|      * +.       |
|     + BSoo      |
|      B=B. .     |
|     oo==B  .    |
|     o=++o...+.. |
|     .*oo. .+=*+o|
+----[SHA256]-----+

将公钥复制到远程机器中

[root@localhost ~]# ssh-copy-id root@192.168.43.111
[root@localhost ~]# ssh-copy-id root@192.168.43.222
[root@localhost ~]# ssh-copy-id root@192.168.43.233

3. 启用 visiblepw

需要3台centos7全部启用!

启用visiblepw:如果连接超时或者失败,会新开一个终端

[root@localhost ~]# vim /etc/sudoers

  1. 创建一个 machine:host1

参数说明:

generic:创建一个machines通过SSH使用已经存在的虚拟机或是主机 如果docker没有运行在主机上,它将被自动安装. 它会更新主机的软件包(apt-get update, yum update). 为了确保docker daemon的安全它会生成证书. docker daemon 将会重启,因此所有正在运行的容器将会停止. 主机的hostname将被更改为machine name. --generic-ip-address 指定目标系统的 IP,并命名为 host1

[root@localhost ~]# docker-machine create --driver generic --generic-ip-address=192.168.43.111 host1

Creating CA: /root/.docker/machine/certs/ca.pem
Creating client certificate: /root/.docker/machine/certs/cert.pem
Running pre-create checks...
Creating machine...
(host1) No SSH key specified. Assuming an existing key at the default location.
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...
Warning: got an invalid line error parsing /etc/os-release: Expected --2019-04-24 02:53:42--  https://raw.githubusercontent.com/docker/machine/v0.16.0/contrib/completion/bash/docker-machine-prompt.bash to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.108.133 to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|151.101.108.133|:443... 已连接。 to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 已发出 HTTP 请求,正在等待回应... 200 OK to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 长度:1469 (1.4K) [text/plain] to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 正在保存至: “/etc/bash_completion.d/docker-machine-prompt.bash.8” to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 2019-04-24 02:53:43 (296 MB/s) - 已保存 “/etc/bash_completion.d/docker-machine-prompt.bash.8” [1469/1469]) to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected --2019-04-24 02:53:43--  https://raw.githubusercontent.com/docker/machine/v0.16.0/contrib/completion/bash/docker-machine-wrapper.bash to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.108.133 to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|151.101.108.133|:443... 已连接。 to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 已发出 HTTP 请求,正在等待回应... 200 OK to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 长度:1525 (1.5K) [text/plain] to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 正在保存至: “/etc/bash_completion.d/docker-machine-wrapper.bash.7” to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 2019-04-24 02:53:44 (278 MB/s) - 已保存 “/etc/bash_completion.d/docker-machine-wrapper.bash.7” [1525/1525]) to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected --2019-04-24 02:53:44--  https://raw.githubusercontent.com/docker/machine/v0.16.0/contrib/completion/bash/docker-machine.bash to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.108.133 to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|151.101.108.133|:443... 已连接。 to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 已发出 HTTP 请求,正在等待回应... 200 OK to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 长度:12211 (12K) [text/plain] to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 正在保存至: “/etc/bash_completion.d/docker-machine.bash.7” to split by '=' char into two strings, instead got 1 strings
Warning: got an invalid line error parsing /etc/os-release: Expected 2019-04-24 02:53:44 (130 KB/s) - 已保存 “/etc/bash_completion.d/docker-machine.bash.7” [12211/12211]) to split by '=' char into two strings, instead got 1 strings
Provisioning with centos...

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 host1

5.  启用docker-machineshell提示符

添加$(__docker_machine_ps1)进你的~/.bashrc.

[root@host1 ~]# vim ~/.bashrc

# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
PS1='[\u@\h \W$(__docker_machine_ps1)]\$ '             # 添加这个到最后一行
[root@host1 ~]# source ~/.bashrc

6. 测试docker是否安装成功

[root@localhost ~]# docker --version
Docker version 18.09.5, build e8ff056
Last modification:July 23rd, 2020 at 11:29 pm
如果觉得我的文章对你有用,请随意赞赏