-1

I have a problem building a docker image for my python server. when running: docker image build -t server:latest . I get the following error:

=> 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

Inside my dockerfile I tried upgrading setuptools, but apparently this is not the problem.
My dockerfile looks like this (I am new to 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"]

The requirements.txt contains only cryptography==38.0.1 and xeddsa==0.6.0

How can I fix it? I am running out of ideas.

SOLUTION: Thanks for the help. I followed the tips from spramuditha. The things I had to install where: build-essential, cmake, protobuf compiler and libsodium

Silent Tree
  • 987
  • 1
  • 7
  • 16
  • 1
    _"The compilation requires CMake and the "make" tool."_ ...have you ensured these packages are installed in the docker container before running pip install? – Anentropic Oct 21 '22 at 11:25
  • 1
    `No such file or directory: 'cmake'` is the key error. Can you adapt, for example, [How to install libraries that require compilation on google-colaboratory](https://stackoverflow.com/questions/48519700/how-to-install-libraries-that-require-compilation-on-google-colaboratory)? – David Maze Oct 21 '22 at 11:25
  • try this https://stackoverflow.com/a/55508937/202168 – Anentropic Oct 21 '22 at 11:28

1 Answers1

3

This can be very frustrating when you see your docker build is ending up in an error time and time over. Something you can try in future;

  1. Create the Dockerfile with upto whatever the point giving an error (Say minimal os image)
  2. Run it in interactive mode with docker run -it <IMAGE_NAME>
  3. Try to install whatever requirements there manually; in this case apt-get update && apt-get -y install cmake protobuf-compiler as mentioned in the comment by @Anentropic Or sometimes even all of these; apt-get update && apt-get install -y gfortran libfreetype6-dev libhdf5-dev liblapack-dev libopenblas-dev libpng-dev && rm -rf /var/lib/apt/lists/* Notice rm -rf /var/lib/apt/lists/* to keep the docker from having unnecessary stuff.
  4. Pay attention to PATHs and etc. If you manage to successfully setup in the iterative environment get the commands that worked and put it in the Dockerfile appropriately.

Hope this helps!

spramuditha
  • 357
  • 2
  • 9