Docker为numpy构建,熊猫给出错误

时间:2019-03-06 21:47:28

标签: docker

我在名为docker_test的目录中有一个Dockerfile。 docker_test的结构如下:

M00618927A:docker_test i854319$ ls 
Dockerfile  hello_world.py

我的dockerfile如下所示:

  ### Dockerfile 

# Created by Baktaawar 

# Pulling from base Python image 

FROM python:3.6.7-alpine3.6

# author of file
LABEL maintainer="Baktawar"

# Set the working directory of the docker image 
WORKDIR /docker_test
COPY . /docker_test


# packages that we need

RUN pip --no-cache-dir install numpy pandas jupyter


EXPOSE 8888

ENTRYPOINT ["python"]

CMD ["hello_world.py"]

我运行命令

docker build -t dockerfile . 

它开始构建过程,但是由于无法获取图像中安装的numpy等而出现以下错误

Sending build context to Docker daemon  4.096kB
Step 1/8 : FROM python:3.6.7-alpine3.6
 ---> 8f30079779ef
Step 2/8 : LABEL maintainer="Baktawar"
 ---> Running in 7cf081021b1e
Removing intermediate container 7cf081021b1e
 ---> 581cf24fa4e6
Step 3/8 : WORKDIR /docker_test
 ---> Running in 7c58855c4332
Removing intermediate container 7c58855c4332
 ---> dae70a34626b
Step 4/8 : COPY . /docker_test
 ---> 432b174b4869
Step 5/8 : RUN pip --no-cache-dir install numpy pandas jupyter
 ---> Running in 972efa9336ed
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/cf/8d/6345b4f32b37945fedc1e027e83970005fc9c699068d2f566b82826515f2/numpy-1.16.2.zip (5.1MB)
Collecting pandas
  Downloading https://files.pythonhosted.org/packages/81/fd/b1f17f7dc914047cd1df9d6813b944ee446973baafe8106e4458bfb68884/pandas-0.24.1.tar.gz (11.8MB)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 357, in get_provider
        module = sys.modules[moduleOrReq]
    KeyError: 'numpy'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-8c3o0ycd/pandas/setup.py", line 732, in <module>
        ext_modules=maybe_cythonize(extensions, compiler_directives=directives),
      File "/tmp/pip-install-8c3o0ycd/pandas/setup.py", line 475, in maybe_cythonize
        numpy_incl = pkg_resources.resource_filename('numpy', 'core/include')
      File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1142, in resource_filename
        return get_provider(package_or_requirement).get_resource_filename(
      File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 359, in get_provider
        __import__(moduleOrReq)
    ModuleNotFoundError: No module named 'numpy'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-8c3o0ycd/pandas/
You are using pip version 18.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip --no-cache-dir install numpy pandas jupyter' returned a non-zero code: 1

如何完成此基本设置?

1 个答案:

答案 0 :(得分:2)

您基本上需要在alpine上安装以下软件,才能安装numpy:

apk --no-cache add musl-dev linux-headers g++

尝试以下Dockerfile:

### Dockerfile
# Created by Baktawar
# Pulling from base Python image

FROM python:3.6.7-alpine3.6

# author of file
LABEL maintainer="Baktawar"

# Set the working directory of the docker image
WORKDIR /app
COPY . /app

# Install native libraries, required for numpy
RUN apk --no-cache add musl-dev linux-headers g++

# Upgrade pip
RUN pip install --upgrade pip

# packages that we need
RUN pip install numpy && \
    pip install pandas && \
    pip install jupyter

EXPOSE 8888

ENTRYPOINT ["python"]

CMD ["hello_world.py"]

您可能会发现以下要点:

https://gist.github.com/orenitamar/f29fb15db3b0d13178c1c4dd611adce2

我认为这个高山包也很有趣:

https://pkgs.alpinelinux.org/package/edge/community/x86/py-numpy

更新

为了正确标记图像,请使用以下语法:

docker build -f <dockerfile> -t <tagname:tagversion> <buildcontext>

对您来说,这将是:

docker build -t mypythonimage:0.1 .