0

I am trying to learn how to convert a Python app to a Docker container.

I have the following files in my folder:

  1. Dockerfile
  2. LIN_trials.py (my Python code)
  3. requirements.txt

My Dockerfile is as follows:

FROM alpine:latest

RUN apk add --no-cache python3-dev && pip3 install --upgrade pip

WORKDIR /app

COPY . /app

RUN pip3 --no-cache-dir install -r requirements.txt

And I have the following in my requirements.txt

numpy==1.13.0
pandas==0.25.0

When I build the image using:

docker build -t mscons_trial .

The first 4 steps run fine, but the step 5 throws the following error:

Step 5/5 : RUN pip3 --no-cache-dir install -r requirements.txt
 ---> Running in 6871e7bfe6a6
Collecting numpy==1.13.0 (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/05/84/0feb999c05f252af50a5fbc463268044feda92cdaad8cb0d0a6073d76057/numpy-1.13.0.zip (5.0MB)
Collecting pandas==0.25.0 (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/0b/1f/8fca0e1b66a632b62cc1ae38e197befe48c5cee78f895edf4bf8d340454d/pandas-0.25.0.tar.gz (12.6MB)
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-gr440tpe/pandas/setup.py'"'"'; __file__='"'"'/tmp/pip-install-gr440tpe/pandas/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /tmp/pip-install-gr440tpe/pandas/
    Complete output (178 lines):
    /bin/sh: svnversion: not found
    non-existing path in 'numpy/distutils': 'site.cfg'
    non-existing path in 'numpy/random': 'src/splitmix64/splitmix.h'
    Could not locate executable gfortran
    Could not locate executable f95
    Could not locate executable ifort
    Could not locate executable ifc
    Could not locate executable lf95
    Could not locate executable pgfortran
    Could not locate executable f90
    Could not locate executable f77
    Could not locate executable fort
    Could not locate executable efort
    Could not locate executable efc
    Could not locate executable g77
    Could not locate executable g95
    Could not locate executable pathf95
    Could not locate executable nagfor
    don't know how to compile Fortran code on platform 'posix'
    Running from numpy source directory.
    /tmp/easy_install-3xmzt6hd/numpy-1.17.2/setup.py:418: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
      run_build = parse_setuppy_commands()
    /tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/system_info.py:690: UserWarning:
        Optimized (vendor) Blas libraries are not found.
        Falls back to netlib Blas library which has worse performance.
        A better performance should be easily gained by switching
        Blas library.
      self.calc_info()
    /tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/system_info.py:690: UserWarning:
        Blas (http://www.netlib.org/blas/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [blas]) or by setting
        the BLAS environment variable.
      self.calc_info()
    /tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/system_info.py:690: UserWarning:
        Blas (http://www.netlib.org/blas/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [blas_src]) or by setting
        the BLAS_SRC environment variable.
      self.calc_info()
    /tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/system_info.py:1712: UserWarning:
        Lapack (http://www.netlib.org/lapack/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [lapack]) or by setting
        the LAPACK environment variable.
      if getattr(self, '_calc_info_{}'.format(lapack))():
    /tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/system_info.py:1712: UserWarning:
        Lapack (http://www.netlib.org/lapack/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [lapack_src]) or by setting
        the LAPACK_SRC environment variable.
      if getattr(self, '_calc_info_{}'.format(lapack))():
    /usr/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'define_macros'
      warnings.warn(msg)
    Traceback (most recent call last):
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 154, in save_modules
        yield saved
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 195, in setup_context
        yield
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 250, in run_setup
        _execfile(setup_script, ns)
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 45, in _execfile
        exec(code, globals, locals)
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/setup.py", line 443, in <module>
        cmdclass["cython"] = CythonCommand
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/setup.py", line 435, in setup_package
        pass
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/core.py", line 171, in setup
      File "/usr/lib/python3.7/site-packages/setuptools/__init__.py", line 145, in setup
        return distutils.core.setup(**attrs)
      File "/usr/lib/python3.7/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/lib/python3.7/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/usr/lib/python3.7/site-packages/setuptools/command/bdist_egg.py", line 163, in run
        self.run_command("egg_info")
      File "/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/command/egg_info.py", line 26, in run
      File "/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/command/build_src.py", line 142, in run
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/command/build_src.py", line 153, in build_sources
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/command/build_src.py", line 286, in build_library_sources
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/command/build_src.py", line 369, in generate_sources
      File "numpy/core/setup.py", line 669, in get_mathlib_info
        "depends": tseries_depends,
    RuntimeError: Broken toolchain: cannot link a simple C program

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-gr440tpe/pandas/setup.py", line 833, in <module>
        **setuptools_kwargs
      File "/usr/lib/python3.7/site-packages/setuptools/__init__.py", line 144, in setup
        _install_setup_requires(attrs)
      File "/usr/lib/python3.7/site-packages/setuptools/__init__.py", line 139, in _install_setup_requires
        dist.fetch_build_eggs(dist.setup_requires)
      File "/usr/lib/python3.7/site-packages/setuptools/dist.py", line 724, in fetch_build_eggs
        replace_conflicting=True,
      File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 782, in resolve
        replace_conflicting=replace_conflicting
      File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1065, in best_match
        return self.obtain(req, installer)
      File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1077, in obtain
        return installer(requirement)
      File "/usr/lib/python3.7/site-packages/setuptools/dist.py", line 791, in fetch_build_egg
        return cmd.easy_install(req)
      File "/usr/lib/python3.7/site-packages/setuptools/command/easy_install.py", line 679, in easy_install
        return self.install_item(spec, dist.location, tmpdir, deps)
      File "/usr/lib/python3.7/site-packages/setuptools/command/easy_install.py", line 705, in install_item
        dists = self.install_eggs(spec, download, tmpdir)
      File "/usr/lib/python3.7/site-packages/setuptools/command/easy_install.py", line 890, in install_eggs
        return self.build_and_install(setup_script, setup_base)
      File "/usr/lib/python3.7/site-packages/setuptools/command/easy_install.py", line 1158, in build_and_install
        self.run_setup(setup_script, setup_base, args)
      File "/usr/lib/python3.7/site-packages/setuptools/command/easy_install.py", line 1144, in run_setup
        run_setup(setup_script, args)
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 253, in run_setup
        raise
      File "/usr/lib/python3.7/contextlib.py", line 130, in __exit__
        self.gen.throw(type, value, traceback)
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 195, in setup_context
        yield
      File "/usr/lib/python3.7/contextlib.py", line 130, in __exit__
        self.gen.throw(type, value, traceback)
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 166, in save_modules
        saved_exc.resume()
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 141, in resume
        six.reraise(type, exc, self._tb)
      File "/usr/lib/python3.7/site-packages/setuptools/_vendor/six.py", line 685, in reraise
        raise value.with_traceback(tb)
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 154, in save_modules
        yield saved
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 195, in setup_context
        yield
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 250, in run_setup
        _execfile(setup_script, ns)
      File "/usr/lib/python3.7/site-packages/setuptools/sandbox.py", line 45, in _execfile
        exec(code, globals, locals)
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/setup.py", line 443, in <module>
        cmdclass["cython"] = CythonCommand
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/setup.py", line 435, in setup_package
        pass
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/core.py", line 171, in setup
      File "/usr/lib/python3.7/site-packages/setuptools/__init__.py", line 145, in setup
        return distutils.core.setup(**attrs)
      File "/usr/lib/python3.7/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/lib/python3.7/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/usr/lib/python3.7/site-packages/setuptools/command/bdist_egg.py", line 163, in run
        self.run_command("egg_info")
      File "/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/command/egg_info.py", line 26, in run
      File "/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/command/build_src.py", line 142, in run
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/command/build_src.py", line 153, in build_sources
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/command/build_src.py", line 286, in build_library_sources
      File "/tmp/easy_install-3xmzt6hd/numpy-1.17.2/numpy/distutils/command/build_src.py", line 369, in generate_sources
      File "numpy/core/setup.py", line 669, in get_mathlib_info
        "depends": tseries_depends,
    RuntimeError: Broken toolchain: cannot link a simple C program
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
The command '/bin/sh -c pip3 --no-cache-dir install -r requirements.txt' returned a non-zero code: 1

I am completely new to Docker, so I don't know if there's a mistake that I am doing.

2
  • Hey @LinPy, I am already doing the pip3 install --upgrade pip as you can see in the RUN Commented Sep 27, 2019 at 8:36
  • I also tried your suggestion of using python:3.8.0b4-alpine3.10, but it gives the same error Commented Sep 27, 2019 at 8:39

3 Answers 3

1

add this to your dockerfile before installing your requirments:

RUN apk update && apk add  --no-cache --virtual build-dependencies libc-dev build-base
1
  • It now shows the following error: in the step 5 (the line suggested by you) ERROR: unsatisfiable constraints: build-dependencies (missing): required by: world[build-dependencies] Commented Sep 27, 2019 at 8:44
0

Try running apk add alpine-sdk in the first command

0

Do debug this I suggest try:

 docker run -it alpine:latest /bin/sh

Which will bring up the sh prompt, then run:

#  echo "numpy==1.13.0" > requirements.txt

# echo "pandas==0.25.0" >> requirements.txt

# apk add --no-cache python3-dev && pip3 install --upgrade pip

# pip3 --no-cache-dir install -r requirements.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.