docker 版本上的 Yarn 警告

Yarn warning on docker build

在我的 docker 容器内 运行 yarn install 时,它会发出有关未连接的警告。 https://hub.docker.com/r/tavern/rpg-web/~/dockerfile/

warning You don't appear to have an internet connection. Try the --offline flag to use the cache for registry queries.

可能是什么原因造成的?

由于您的 Docker 文件中有一行内容为 RUN yarn(即不使用 yarn 的离线选项),yarn 会尝试确定互联网是否可能自动可用而不发送任何数据包。

yarn如何查看在线状态?

这是通过使用节点的 os.networkInterfaces(), which is documented here.

在 docker 构建器上下文中枚举可用的网络接口来完成的

这又会调用 GetInterfaceAddresses which is backed by libuv's uv_interface_addresses。 libuv 函数仅 returns 接口分配了 IP 地址并设置了 IFF_UPIFF_RUNNING 标志。

要查看哪些地址实际返回给 Javascript 代码,您可以暂时将此行添加到您的 Docker 文件中:

RUN node -e 'const os = require("os"); const interfaces = os.networkInterfaces(); for (const interface in interfaces) {console.log(interface); const addrs = interfaces[interface]; for (const addr of addrs) {console.log(addr.address)}}'

至少在我的例子中,这只返回了环回地址,纱线在 1:

中明确忽略了该地址

lo 127.0.0.1 ::1

但是 docker 图像中的 运行 ifconfig 也显示了 eth0 界面。此接口的 HWaddr 与 运行 docker 守护程序机器上的 docker0 接口相匹配。这表明构建器上下文与 docker 桥接网络一起运行。

那么从 libuv 的列表中排除桥接网络的标准是什么?

在我的例子中,docker 网络没有设置 IFF_RUNNING。这并不奇怪,因为 Linux documentation 说这个字段是为了向后兼容。

要验证您的实例是否属于这种情况,您可以使用 this document 中示例程序的稍微修改版本,在第一个 printf() 调用之后添加此代码:

printf("RUNNING: %s", (ifa->ifa_flags & IFF_RUNNING) ? "TRUE" : "FALSE");

为什么 docker 没有设置 IFF_RUNNING

设置接口标志是一个低级操作,docker 不会自行处理。 Docker 的 libnetwork 委托给 netlink 库 here, but netlink only sets IFF_UP.

如何解决?

这个问题的相关移动部分是开源的!

netlink 是 changed 公开 IFF_RUNNING 供阅读 - 可以启用 libnetwork(因此 docker)通过进一步更改 netlink 来设置该标志。

或者,libuv 可能会在 Github issue on the subject 之后扩展。这样一个新的 API 最终可以在 node.js 和 yarn 中使用,无论分配的 IP 地址和 IFF_RUNNING 状态如何,它都会列出接口。