我在为我的python服务器构建docker映像时遇到了问题。运行:docker image build -t server:latest .
时,我收到以下错误:
=> ERROR [4/6] RUN pip3 install -r requirements.txt 11.2s
------
> [4/6] RUN pip3 install -r requirements.txt:
# 9 1.220 Collecting cryptography==38.0.1
# 9 1.328 Downloading cryptography-38.0.1-cp36-abi3-manylinux_2_28_x86_64.whl (4.2 MB)
# 9 2.034 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.2/4.2 MB 5.9 MB/s eta 0:00:00
# 9 2.084 Collecting xeddsa==0.6.0
# 9 2.099 Downloading XEdDSA-0.6.0.tar.gz (89 kB)
# 9 2.117 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 89.5/89.5 KB 5.6 MB/s eta 0:00:00
# 9 2.153 Preparing metadata (setup.py): started
# 9 10.94 Preparing metadata (setup.py): finished with status 'error'
# 9 10.95 error: subprocess-exited-with-error
# 9 10.95
# 9 10.95 × python setup.py egg_info did not run successfully.
# 9 10.95 │ exit code: 1
# 9 10.95 ╰─> [58 lines of output]
# 9 10.95 Collecting cmake
# 9 10.95 Downloading cmake-3.24.1.1-py2.py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.3 MB)
# 9 10.95 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 23.3/23.3 MB 5.5 MB/s eta 0:00:00
# 9 10.95 Installing collected packages: cmake
# 9 10.95 WARNING: The scripts cmake, cpack and ctest are installed in '/root/.local/bin' which is not on PATH.
# 9 10.95 Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
# 9 10.95 Successfully installed cmake-3.24.1.1
# 9 10.95 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
# 9 10.95 WARNING: You are using pip version 22.0.4; however, version 22.3 is available.
# 9 10.95 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
# 9 10.95 /usr/local/lib/python3.8/site-packages/setuptools/installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
# 9 10.95 warnings.warn(
# 9 10.95 Traceback (most recent call last):
# 9 10.95 File "ref10/build.py", line 39, in call_cmake
# 9 10.95 subprocess.check_call([ "cmake", "-G", output, ".." ], cwd = build_dir)
# 9 10.95 File "/usr/local/lib/python3.8/subprocess.py", line 359, in check_call
# 9 10.95 retcode = call(*popenargs,**kwargs)
# 9 10.95 File "/usr/local/lib/python3.8/subprocess.py", line 340, in call
# 9 10.95 with Popen(*popenargs,**kwargs) as p:
# 9 10.95 File "/usr/local/lib/python3.8/subprocess.py", line 858, in __init__
# 9 10.95 self._execute_child(args, executable, preexec_fn, close_fds,
# 9 10.95 File "/usr/local/lib/python3.8/subprocess.py", line 1704, in _execute_child
# 9 10.95 raise child_exception_type(errno_num, err_msg, err_filename)
# 9 10.95 FileNotFoundError: [Errno 2] No such file or directory: 'cmake'
# 9 10.95
# 9 10.95 During handling of the above exception, another exception occurred:
# 9 10.95
# 9 10.95 Traceback (most recent call last):
# 9 10.95 File "<string>", line 2, in <module>
# 9 10.95 File "<pip-setuptools-caller>", line 34, in <module>
# 9 10.95 File "/tmp/pip-install-27a8cwpi/xeddsa_5642cb3382374f11abad1422799f8339/setup.py", line 51, in <module>
# 9 10.95 setup(
# 9 10.95 File "/usr/local/lib/python3.8/site-packages/setuptools/__init__.py", line 87, in setup
# 9 10.95 return distutils.core.setup(**attrs)
# 9 10.95 File "/usr/local/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 147, in setup
# 9 10.95 _setup_distribution = dist = klass(attrs)
# 9 10.95 File "/usr/local/lib/python3.8/site-packages/setuptools/dist.py", line 476, in __init__
# 9 10.95 _Distribution.__init__(
# 9 10.95 File "/usr/local/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 282, in __init__
# 9 10.95 self.finalize_options()
# 9 10.95 File "/usr/local/lib/python3.8/site-packages/setuptools/dist.py", line 900, in finalize_options
# 9 10.95 ep(self)
# 9 10.95 File "/usr/local/lib/python3.8/site-packages/setuptools/dist.py", line 920, in _finalize_setup_keywords
# 9 10.95 ep.load()(self, ep.name, value)
# 9 10.95 File "/tmp/pip-install-27a8cwpi/xeddsa_5642cb3382374f11abad1422799f8339/.eggs/cffi-1.15.1-py3.8-linux-x86_64.egg/cffi/setuptools_ext.py", line 219, in cffi_modules
# 9 10.95 add_cffi_module(dist, cffi_module)
# 9 10.95 File "/tmp/pip-install-27a8cwpi/xeddsa_5642cb3382374f11abad1422799f8339/.eggs/cffi-1.15.1-py3.8-linux-x86_64.egg/cffi/setuptools_ext.py", line 49, in add_cffi_module
# 9 10.95 execfile(build_file_name, mod_vars)
# 9 10.95 File "/tmp/pip-install-27a8cwpi/xeddsa_5642cb3382374f11abad1422799f8339/.eggs/cffi-1.15.1-py3.8-linux-x86_64.egg/cffi/setuptools_ext.py", line 25, in execfile
# 9 10.95 exec(code, glob, glob)
# 9 10.95 File "ref10/build.py", line 76, in <module>
# 9 10.95 call_cmake("Unix Makefiles")
# 9 10.95 File "ref10/build.py", line 55, in call_cmake
# 9 10.95 os.path.append(os.path.expanduser("~/.local/bin"))
# 9 10.95 AttributeError: module 'posixpath' has no attribute 'append'
# 9 10.95 Attempting to compile the ref10 library...
# 9 10.95 The compilation requires CMake and the "make" tool.
# 9 10.95 The "cmake" and "make" commands are used.
# 9 10.95 [end of output]
# 9 10.95
# 9 10.95 note: This error originates from a subprocess, and is likely not a problem with pip.
# 9 10.96 error: metadata-generation-failed
# 9 10.96
# 9 10.96 × Encountered error while generating package metadata.
# 9 10.96 ╰─> See above for output.
# 9 10.96
# 9 10.96 note: This is an issue with the package mentioned above, not pip.
# 9 10.96 hint: See above for details.
# 9 10.96 WARNING: You are using pip version 22.0.4; however, version 22.3 is available.
# 9 10.96 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
------
executor failed running [/bin/sh -c pip3 install -r requirements.txt]: exit code: 1
在我的dockerfile中,我尝试升级setupTools,但显然这不是问题所在。
我的docker文件如下所示(我是新来的docker):
FROM python:3.8-slim-buster
WORKDIR .
COPY requirements.txt requirements.txt
RUN pip3 install --upgrade setuptools
RUN pip3 install -r requirements.txt
COPY . .
CMD ["python3", "./server.py"]
Requirements.txt仅包含加密==38.0.1和xeddsa==0.6.0
我怎么才能修好它?我的点子快用完了。
解决方案:谢谢你的帮助。我听从了Spramuditha的建议。我必须安装在哪里:Build-Essential、cmake、Protobuf编译器和libNa
1条答案
按热度按时间lymnna711#
当您一次又一次地看到您的docker构建在错误中结束时,这可能会非常令人沮丧。一些你将来可以尝试的东西;
1.创建Dockerfile,直到出现错误(比如最小的操作系统镜像)
1.使用docker run-it<IMAGE_NAME>以交互模式运行
1.尝试在那里手动安装任何要求;在这种情况下,@Aneypic的评论中提到的
apt-get update && apt-get -y install cmake protobuf-compiler
,有时甚至是所有这些;apt-get update && apt-get install -y gfortran libfreetype6-dev libhdf5-dev liblapack-dev libopenblas-dev libpng-dev && rm -rf /var/lib/apt/lists/*
通知rm -rf /var/lib/apt/lists/*
,以防止docker拥有不必要的东西。1.注意路径等。如果在迭代环境中成功设置,则获取有效的命令,并将其适当地放入Dockerfile中。
希望这个能帮上忙!