设置远程 docker 服务器时出错
error when setting up remote docker server
在我的 Pi 上,我按照 this tutorial 在 raspbian 上安装了 docker。这里有一些旁注:
- 我没有设置 swarm,我在 docker info 处停了下来(和其他指南一样)我成功地 运行 hello world 容器。
- idk 如果它很重要,但本指南(与其他指南不同)让我编辑
/etc/apt/sources.list
并添加行:deb https://download.docker.com/linux/raspbian/ stretch stable
在我的开发机器 (win 10) 上,我使用 this tutorial 将 docker 配置和 yml 添加到我的 mern 堆栈应用程序。然而,在本教程的多个点上,他们希望我使用 运行 docker 命令,所以我最终不得不安装 Docker Desktop。
但我不想使用本地容器,我想在我的 Pi 上使用远程容器。所以我使用 this tutorial 尝试设置我的遥控器 docker.
但是我得到一个错误:
C:\Users\oweng>docker-machine create --driver generic
--generic-ip-address=192.168.1.2 --generic-ssh-key "%HOMEPATH%/.ssh/id_rsa" --generic-ssh-user=pi remote-docker-host
Running pre-create checks... Creating machine... (remote-docker-host)
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... Enter passphrase for key
'C:\Users\oweng.docker\machine\machines\remote-docker-host\id_rsa':
Enter passphrase for key
'C:\Users\oweng.docker\machine\machines\remote-docker-host\id_rsa':
Detecting the provisioner... Enter passphrase for key
'C:\Users\oweng.docker\machine\machines\remote-docker-host\id_rsa':
Error creating machine: Error detecting OS: OS type not recognized
我用谷歌搜索了一下错误,但没有找到解决方案。
此外,在我的 Pi(docker 服务器)上检查监听端口时,我没有看到它 运行ning
pi@raspberrypi:~ $ sudo lsof -i -P -n | grep LISTEN xrdp-sesm 390
root 7u IPv6 14566 0t0 TCP [::1]:3350 (LISTEN) sshd
404 root 3u IPv4 17224 0t0 TCP *:22 (LISTEN) sshd
404 root 4u IPv6 17226 0t0 TCP *:22 (LISTEN) xrdp
406 xrdp 11u IPv6 17302 0t0 TCP *:3389 (LISTEN)
所以我觉得服务器可能不是 运行ning?不过好像是。
pi@raspberrypi:~ $ systemctl status docker ● docker.service - Docker
Application Container Engine Loaded: loaded
(/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-11-03 07:18:21 PST; 3h 35min
ago
Docs: https://docs.docker.com Main PID: 496 (dockerd)
Tasks: 13 CGroup: /system.slice/docker.service
└─496 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Nov 03 07:18:14 raspberrypi dockerd[496]:
time="2020-11-03T07:18:14.064113743-08:00" level=warning msg="Your
kernel does not support cgroup blkio throttle.w Nov 03 07:18:14
raspberrypi dockerd[496]: time="2020-11-03T07:18:14.064249212-08:00"
level=warning msg="Your kernel does not support cgroup blkio
throttle.r Nov 03 07:18:14 raspberrypi dockerd[496]:
time="2020-11-03T07:18:14.064373483-08:00" level=warning msg="Your
kernel does not support cgroup blkio throttle.w Nov 03 07:18:14
raspberrypi dockerd[496]: time="2020-11-03T07:18:14.066367493-08:00"
level=info msg="Loading containers: start." Nov 03 07:18:17
raspberrypi dockerd[496]: time="2020-11-03T07:18:17.612685200-08:00"
level=info msg="Default bridge (docker0) is assigned with an IP
address Nov 03 07:18:18 raspberrypi dockerd[496]:
time="2020-11-03T07:18:18.710629367-08:00" level=info msg="Loading
containers: done." Nov 03 07:18:20 raspberrypi dockerd[496]:
time="2020-11-03T07:18:20.815943637-08:00" level=info msg="Docker
daemon" commit=4484c46 graphdriver(s)=overlay2 v Nov 03 07:18:20
raspberrypi dockerd[496]: time="2020-11-03T07:18:20.822947178-08:00"
level=info msg="Daemon has completed initialization" Nov 03 07:18:21
raspberrypi systemd1: Started Docker Application Container Engine.
Nov 03 07:18:21 raspberrypi dockerd[496]:
time="2020-11-03T07:18:21.273201136-08:00" level=info msg="API listen
on /var/run/docker.sock"
更新 1
在 post 之后,我似乎能够获得服务器 运行ning。正在编辑 docker.service 文件。我现在在尝试创建时遇到不同的错误
C:\Users\oweng>docker-machine create --driver generic
--generic-ip-address=192.168.1.2:2137 --generic-ssh-key "%HOMEPATH%/.ssh/id_rsa" --generic-ssh-user=pi remote-docker-host
Running pre-create checks... Creating machine... (remote-docker-host)
Importing SSH key... Waiting for machine to be running, this may take
a few minutes... Error creating machine: Error waiting for machine to
be running: Maximum number of retries (60) exceeded
更新 2
BMitch 的评论将我带到了这两个教程,这似乎正是我想要做的
https://code.visualstudio.com/docs/containers/ssh
https://code.visualstudio.com/docs/containers/choosing-dev-environment#_remote-machine
我不会为此使用 docker-machine
。对该工具的支持似乎正在消失,并且有更简单的方法。
最简单的是在你的机器上设置DOCKER_HOST
作为远程节点的ssh设置:
export DOCKER_HOST=ssh://user@host
docker info # should now show the remote host if you have ssh access
如果您发现自己在节点之间经常变化,我建议您设置一个上下文,然后不设置 DOCKER_HOST:
unset DOCKER_HOST
docker context create rpi --description "Pi" --docker "host=ssh://user@host"
docker --context rpi info
然后您可以使用
将上下文设为新的默认值
docker context use rpi
然后切换回 local/default docker 引擎
docker context use default
在我的 Pi 上,我按照 this tutorial 在 raspbian 上安装了 docker。这里有一些旁注:
- 我没有设置 swarm,我在 docker info 处停了下来(和其他指南一样)我成功地 运行 hello world 容器。
- idk 如果它很重要,但本指南(与其他指南不同)让我编辑
/etc/apt/sources.list
并添加行:deb https://download.docker.com/linux/raspbian/ stretch stable
在我的开发机器 (win 10) 上,我使用 this tutorial 将 docker 配置和 yml 添加到我的 mern 堆栈应用程序。然而,在本教程的多个点上,他们希望我使用 运行 docker 命令,所以我最终不得不安装 Docker Desktop。
但我不想使用本地容器,我想在我的 Pi 上使用远程容器。所以我使用 this tutorial 尝试设置我的遥控器 docker.
但是我得到一个错误:
C:\Users\oweng>docker-machine create --driver generic --generic-ip-address=192.168.1.2 --generic-ssh-key "%HOMEPATH%/.ssh/id_rsa" --generic-ssh-user=pi remote-docker-host Running pre-create checks... Creating machine... (remote-docker-host) 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... Enter passphrase for key 'C:\Users\oweng.docker\machine\machines\remote-docker-host\id_rsa': Enter passphrase for key 'C:\Users\oweng.docker\machine\machines\remote-docker-host\id_rsa': Detecting the provisioner... Enter passphrase for key 'C:\Users\oweng.docker\machine\machines\remote-docker-host\id_rsa': Error creating machine: Error detecting OS: OS type not recognized
我用谷歌搜索了一下错误,但没有找到解决方案。
此外,在我的 Pi(docker 服务器)上检查监听端口时,我没有看到它 运行ning
pi@raspberrypi:~ $ sudo lsof -i -P -n | grep LISTEN xrdp-sesm 390 root 7u IPv6 14566 0t0 TCP [::1]:3350 (LISTEN) sshd
404 root 3u IPv4 17224 0t0 TCP *:22 (LISTEN) sshd
404 root 4u IPv6 17226 0t0 TCP *:22 (LISTEN) xrdp
406 xrdp 11u IPv6 17302 0t0 TCP *:3389 (LISTEN)
所以我觉得服务器可能不是 运行ning?不过好像是。
pi@raspberrypi:~ $ systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2020-11-03 07:18:21 PST; 3h 35min ago Docs: https://docs.docker.com Main PID: 496 (dockerd) Tasks: 13 CGroup: /system.slice/docker.service └─496 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Nov 03 07:18:14 raspberrypi dockerd[496]: time="2020-11-03T07:18:14.064113743-08:00" level=warning msg="Your kernel does not support cgroup blkio throttle.w Nov 03 07:18:14 raspberrypi dockerd[496]: time="2020-11-03T07:18:14.064249212-08:00" level=warning msg="Your kernel does not support cgroup blkio throttle.r Nov 03 07:18:14 raspberrypi dockerd[496]: time="2020-11-03T07:18:14.064373483-08:00" level=warning msg="Your kernel does not support cgroup blkio throttle.w Nov 03 07:18:14 raspberrypi dockerd[496]: time="2020-11-03T07:18:14.066367493-08:00" level=info msg="Loading containers: start." Nov 03 07:18:17 raspberrypi dockerd[496]: time="2020-11-03T07:18:17.612685200-08:00" level=info msg="Default bridge (docker0) is assigned with an IP address Nov 03 07:18:18 raspberrypi dockerd[496]: time="2020-11-03T07:18:18.710629367-08:00" level=info msg="Loading containers: done." Nov 03 07:18:20 raspberrypi dockerd[496]: time="2020-11-03T07:18:20.815943637-08:00" level=info msg="Docker daemon" commit=4484c46 graphdriver(s)=overlay2 v Nov 03 07:18:20 raspberrypi dockerd[496]: time="2020-11-03T07:18:20.822947178-08:00" level=info msg="Daemon has completed initialization" Nov 03 07:18:21 raspberrypi systemd1: Started Docker Application Container Engine. Nov 03 07:18:21 raspberrypi dockerd[496]: time="2020-11-03T07:18:21.273201136-08:00" level=info msg="API listen on /var/run/docker.sock"
更新 1
在
C:\Users\oweng>docker-machine create --driver generic --generic-ip-address=192.168.1.2:2137 --generic-ssh-key "%HOMEPATH%/.ssh/id_rsa" --generic-ssh-user=pi remote-docker-host Running pre-create checks... Creating machine... (remote-docker-host) Importing SSH key... Waiting for machine to be running, this may take a few minutes... Error creating machine: Error waiting for machine to be running: Maximum number of retries (60) exceeded
更新 2 BMitch 的评论将我带到了这两个教程,这似乎正是我想要做的 https://code.visualstudio.com/docs/containers/ssh https://code.visualstudio.com/docs/containers/choosing-dev-environment#_remote-machine
我不会为此使用 docker-machine
。对该工具的支持似乎正在消失,并且有更简单的方法。
最简单的是在你的机器上设置DOCKER_HOST
作为远程节点的ssh设置:
export DOCKER_HOST=ssh://user@host
docker info # should now show the remote host if you have ssh access
如果您发现自己在节点之间经常变化,我建议您设置一个上下文,然后不设置 DOCKER_HOST:
unset DOCKER_HOST
docker context create rpi --description "Pi" --docker "host=ssh://user@host"
docker --context rpi info
然后您可以使用
将上下文设为新的默认值docker context use rpi
然后切换回 local/default docker 引擎
docker context use default