运行相同docker命令的两台主机之间存在差异

我和一位同事有一个很大的 Docker 难题。

当我们运行以下命令时,我们会得到不同的结果。

docker run -it python:3.8.6 /bin/bash
pip install fbprophet

对我来说,它安装得很好,而对他来说,它会产生错误并且无法安装。我认为 docker 的全部意义在于防止这种问题,所以我真的很困惑。

我在下面提供更多细节,但我的主要问题是:

  • 我们怎么可能得到不同的结果?

更多细节:

我们都在 Catalina 上的具有相似规格的新 MacBook Pro 上运行 Docker。他的 Docker 引擎版本 20.xx 比我的 19.XX 略新 还有:

  • 他尝试了所有他能想到的命令来清理 Docker 中的东西。
  • 我们验证了图像 ID 的哈希值是否相同。
  • 我们的资源设置也是一样的。
  • 他尝试重新安装Docker并更改为其他版本的python(3.7)。
  • 在过去的三天里,我们同时进行了多次尝试。

结果总是一样:他得到错误而我没有。

他得到的错误如下。

Error:
Installing collected packages: six, pytz, python-dateutil, pymeeus, numpy, pyparsing, pillow, pandas, korean-lunar-calendar, kiwisolver, ephem, Cython, cycler, convertdate, tqdm, setuptools-git, pystan, matplotlib, LunarCalendar, holidays, cmdstanpy, fbprophet
    Running setup.py install for fbprophet ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘“’”‘/tmp/pip-install-l516b8ts/fbprophet_80d5f400081541a2bf6ee26d2785e363/setup.py’“‘”’; __file__=‘“’”‘/tmp/pip-install-l516b8ts/fbprophet_80d5f400081541a2bf6ee26d2785e363/setup.py’“‘”’;f=getattr(tokenize, ‘“’”‘open’“‘”’, open)(__file__);code=f.read().replace(‘“’”‘rn’“‘”’, ‘“’”‘n’“‘”’);f.close();exec(compile(code, __file__, ‘“’”‘exec’“‘”’))' install --record /tmp/pip-record-7n8tvfkb/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.8/fbprophet
         cwd: /tmp/pip-install-l516b8ts/fbprophet_80d5f400081541a2bf6ee26d2785e363/
    Complete output (10 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib
    creating build/lib/fbprophet
    creating build/lib/fbprophet/stan_model
    Importing plotly failed. Interactive plots will not work.
    INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_dfdaf2b8ece8a02eb11f050ec701c0ec NOW.
    error: command ‘gcc’ failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘“’”‘/tmp/pip-install-l516b8ts/fbprophet_80d5f400081541a2bf6ee26d2785e363/setup.py’“‘”’; __file__=‘“’”‘/tmp/pip-install-l516b8ts/fbprophet_80d5f400081541a2bf6ee26d2785e363/setup.py’“‘”’;f=getattr(tokenize, ‘“’”‘open’“‘”’, open)(__file__);code=f.read().replace(‘“’”‘rn’“‘”’, ‘“’”‘n’“‘”’);f.close();exec(compile(code, __file__, ‘“’”‘exec’“‘”’))' install --record /tmp/pip-record-7n8tvfkb/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.8/fbprophet Check the logs for full command output.

请注意,运行我提供的两个命令总是会产生错误,但它们并不重要。在 fbprophet 解决这些小错误之前升级 setuptools 并安装依赖项。上面显示的错误是不同的,与gcc有关,并且只发生在一些人身上。

可选的附加问题:

  • 我们如何修复它?
  • 我们如何防止像这样的不可重复的结果?
  • 升级 docker 引擎版本会破坏容器吗?

回答

我们如何修复它?

您的错误报告了 GCC/编译问题。
快速搜索主要显示与 python/gcc 版本(一、二、三)相关的问题。
但是你是对的,这看起来不像是在一个特定的容器内发生的。

确实看起来就像是某种OOM问题。

另外,这是虚拟机吗?Stan 需要大量内存来编译模型,如果在编译时内存不足,就会发生此错误。

我做了一些测试。
在我的机器上,编译过程消耗了多达 2.4 Gb 的 RAM。

cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

uname -r
3.10.0-1160.6.1.el7.x86_64

docker --version
Docker version 20.10.1, build 831ebea

# works fine
docker run --rm -it -m 3G python:3.8.6 /bin/bash

# fails with error: command 'gcc' failed with exit status 1
# actually it was killed by OOM killer
docker run --rm -it -m 2G python:3.8.6 /bin/bash

# yes, here he is
tail -f /var/log/messages | grep -i 'killed process'
Dec 22 08:34:09 cent7-1 kernel: Killed process 5631 (cc1plus), UID 0, total-vm:2073600kB, anon-rss:1962404kB, file-rss:15332kB, shmem-rss:0kB
Dec 22 08:35:56 cent7-1 kernel: Killed process 5640 (cc1plus), UID 0, total-vm:2056816kB, anon-rss:1947392kB, file-rss:15308kB, shmem-rss:0kB

在有问题的机器上检查 OOM 杀手登录。
是否有足够的内存供 Docker 使用?


升级 docker 引擎版本会破坏容器吗?

一般来说,不应该是这样。
但是v20.10.0Docker 引入了一组非常大的与内存和 cgroups 相关的变化。

在排除所有明显的原因(例如您朋友的机器没有足够的 RAM)之后,您可能需要深入研究与内存 / cgroups / 等相关的 docker 守护程序设置。


同一个容器如何在两台电脑上产生不同的结果?

嗯,从技术上讲,这是完全可能的。
容器化程序仍然使用主机操作系统内核。
并非所有内核设置都是“命名空间”的,即可以专门为一个特定容器设置。
它们中的很多(实际上,大多数)仍然是全局的,并且会影响您的程序的行为。

虽然我认为这与您的问题无关。
但是对于依赖于特定内核设置的复杂程序,必须加以考虑。


以上是运行相同docker命令的两台主机之间存在差异的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>