我是靠谱客的博主 大力鸵鸟,这篇文章主要介绍Windows 10 Docker Machine 部署 Ubuntu18.04LTS 主机,现在分享给大家,希望可以做个参考。

1. 安装 Docker Machine

若是安装了Git,可以使用Git bash执行下面命令:

复制代码
1
2
3
4
$ base=https://github.com/docker/machine/releases/download/v0.16.0 && mkdir -p "$HOME/bin" && curl -L $base/docker-machine-Windows-x86_64.exe > "$HOME/bin/docker-machine.exe" && chmod +x "$HOME/bin/docker-machine.exe"

或是链接外网的环境很好,从网页直接下载:

复制代码
1
https://github.com/docker/machine/releases

 本人上面都试过没通过,只能求助朋友,下载了。

以管理员身份运行Powershell,

复制代码
1
2
3
4
5
6
7
8
9
10
11
PS C:WINDOWSsystem32> cd PS C:Usersach> mkdir -p bin PS C:Usersach> cd .bin PS C:Usersachbin> pwd Path ---- C:Usersachbin PS C:Usersachbin>

把下载的文件拷贝到 C:Usersachbin,并重命名为:docker-machine.exe

把 C:Usersachbin,添加到环境变量PATH路径中

复制代码
1
2
3
PS C:Usersach> docker-machine.exe version docker-machine.exe version 0.16.2, build bd45ab13 PS C:Usersach>

这样就装完成了。

2. Ubuntu 配置 SSH 免密码登录

Ubuntu 使用的是18.04LTS Desktop 版本 IP地址:192.168.1.120

安装ssh server

验证sshd服务

网上大多使用scp拷贝到目标端,并重命名为 authorized_keys,并调整权限;老是记不清权限设置成什么,通常采用下面方法:

在Ubuntu本机,先生成rsa秘钥对,

再使用ssh-copy-id ,配置自己ssh自己的免密码登录,即验证了ssh免密码登录,还自动生成了authorized_keys文件,位置权限都不需要关心。

验证免密码登录

 

 3. 配置 Windows 免密码到 Ubuntu

安装Openssh,生成rsa秘钥

请参照:后期补充链接地址

 

秘钥拷贝到 Ubuntu

登录到Ubuntu ,把秘钥追加到authorized_keys

 exit,并验证免密码登录

免密码登录成功。

4. 使用docker-machine远程配置Ubuntu的docker运行环境

为了减少异常,使用管理员权限运行powershell,由于docker-machine通过ssh远程执行命令时,需要用户有sudo权限,并且需要免密码

注意两点:

NOPASSWD: ALL 之间(红色部分)是有一个空格的。

2 一定要在最后一行添加,否则会被前面的(包括以%开始的那几句)覆盖。

这里参考https://blog.csdn.net/phoenix198425/article/details/78300920,第一点测试是没有空格也能正常生效了

若是没有配置免秘钥,在--debug模式下会提示以下错误:

链接Linux服务器一般使用 generic 驱动:

复制代码
1
docker-machine.exe create --driver generic --generic-ip-address=192.168.1.120 --generic-ssh-key=.ssh/id_rsa --generic-ssh-user=sleeber Machine-120

由于是在powershell环境,--generic-ssh-key使用绝对路径会出错,建议cd到主目录,使用相对路径,主要参数意义如下:

上面的方式docker-machine 会自动安装 docker

但是,受国内网络环境影像,一般是要等不少时间。安装过程中,默认是不打印执行日志的,可以使用 --debug 参数,实时查看状态:

复制代码
1
docker-machine.exe --debug create --driver generic --generic-ip-address=192.168.1.120 --generic-ssh-key=.ssh/id_rsa --generic-ssh-user=sleeber Machine-120

中途使用ctrl+C中止执行,并用 rm 删除 主机

若是网路环境好的话可以安装完成,我这里一直失败,只能手动安装docker,然后使用docker-machine连接到Ubuntu

可以参照:https://docs.docker.com/install/linux/docker-ce/ubuntu/,不再说明。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
sudo apt-get remove docker docker-engine docker.io containerd runc sudo apt-get update sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common //使用官方推荐源{不推荐} curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo apt-key fingerprint 0EBFCD88 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" //使用阿里云的源{推荐} curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" //软件源升级 sudo apt-get update //安装docker sudo apt-get install docker-ce docker-ce-cli containerd.io //若是 安装containerd.io 缺少libseccomp2依赖 https://packages.debian.org/pt-br/sid/libseccomp2 //可以指定版本安装docker: sudo apt-get install docker-ce=<VERSION> -y //查看支持的docker版本 sudo apt-cache madison docker-ce

 docker 手动安装完成之后,使用docker-machine链接:

 

然后是等待安装完成,并检查状态

测试Docker主机

运行Docker Hello-World

至此,Docker Machine 可以连接 Ubuntu18.04LTS Docker主机了。

最后

以上就是大力鸵鸟最近收集整理的关于Windows 10 Docker Machine 部署 Ubuntu18.04LTS 主机的全部内容,更多相关Windows内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部