1. 程式人生 > 其它 >Docker Machine 安裝使用教程

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