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

Discrepancy between two hosts running the same docker commands

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

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

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

对我来说,它安装完美,而对他来说,它会产生错误并无法安装。我以为docker的全部意义就是为了防止这种问题,所以我真的很困惑。

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

更多详情:

我们都 运行宁 Docker 在 Catalina 上使用具有相似规格的新 MacBook Pro。他的 Docker 引擎版本 20.x.x 比我的 19.X.X 稍新。还有:

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

他得到的错误如下。

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(‘“’”‘\r\n’“‘”’, ‘“’”‘\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(‘“’”‘\r\n’“‘”’, ‘“’”‘\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上的问题,而是fbprophet本身造成的。要避免:

docker run -it python:3.8.6 /bin/bash
pip install numpy pandas blahblah...
pip install fbprophet

我们如何解决它?

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

看起来像是某种 OOM problem

Also, is this a VM? Stan requires a significant amount of memory to compile the models, and this error can occur if you run out of RAM while it is compiling.

我做了一些测试。
在我的机器上,编译过程消耗了高达 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 killer 日志。
Docker 是否有足够的可用内存?


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

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

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


同一个容器在两台电脑上怎么会产生不同的结果?

嗯,从技术上讲这是完全可能的。
容器化程序 still use host OS kernel.
并非所有内核设置都是“命名空间”,即。 e.可以专门为一个特定的容器设置。
其中很多(实际上是大多数)仍然是全局的,并且会影响程序的行为。

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