Docker 图像在笔记本电脑上构建,而不是在 Digital Ocean 上构建 - 我对 Docker 的理解被打破了

Docker image builds on laptop, not on Digital Ocean - my understanding of Docker is shattered

我有一个非常重要的 Docker 环境,用于我正在构建的 Python 应用程序(请参阅下面的完整 Dockerfile)。在我的 MacBook(使用 Docker version 1.10.3, build 20f81dd)上,我能够构建 Docker 图像,运行 容器和应用程序工作正常。

我现在想在 Digital Ocean 上测试应用程序。到目前为止,我只在笔记本电脑上使用过 Docker。我使用 Ubuntu Docker 1.10.3 on 14.04 图像创建了一个 Droplet。我通过 SSH 登录,克隆了我的 git 存储库,执行了 docker build 命令,但是我在构建过程中遇到了一个错误(完整堆栈跟踪见底部)。

Exception: Cython-generated file 'pandas/index.c' not found.
           Cython is required to compile pandas from a development branch.
           Please install Cython or download a release package of pandas. 

这是一个有效的例外,但我的问题是:为什么相同的 Dockerfiledocker build 命令会在一台机器上成功构建,但会引发另一个例外? 我对 Docker 的理解是它通过仅使用 Docker 文件从头开始构建环境来防止这种事情发生。 .我只是想不通是什么原因在一台机器上而不是另一台机器上导致了这个异常。


Dockerfile

FROM python:2.7

ENV HOME /root

# Install dependencies
RUN apt-get update \
    && apt-get upgrade -y
RUN apt-get install -y apt-utils
RUN apt-get install -y gcc
RUN apt-get install -y build-essential
RUN apt-get install -y zlib1g-dev
RUN apt-get install -y wget
RUN apt-get install -y unzip
RUN apt-get install -y cmake
RUN apt-get install -y gfortran 
RUN apt-get install -y libatlas-base-dev 
RUN apt-get install -y python-pip 
RUN apt-get install -y python-dev
RUN apt-get install -y subversion
RUN apt-get install -y supervisor
RUN apt-get install -y nginx
RUN apt-get clean

# Install Python packages
RUN pip install --upgrade pip
RUN pip install numpy
RUN pip install pandas
RUN pip install bottleneck
RUN pip install boto3
RUN pip install scipy
RUN pip install Flask
RUN pip install uwsgi

# Build OpenCV and dependencies
RUN cd && wget https://github.com/Itseez/opencv/archive/3.1.0.zip \
    && git clone https://github.com/Itseez/opencv_contrib.git \
        && unzip 3.1.0.zip \
        && cd opencv-3.1.0 && mkdir build && cd build \
        && cmake -D CMAKE_BUILD_TYPE=RELEASE \
             -D CMAKE_INSTALL_PREFIX=/usr/local \
             -D INSTALL_C_EXAMPLES=OFF \
             -D INSTALL_PYTHON_EXAMPLES=ON \
             -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
             -D BUILD_EXAMPLES=ON .. \
    && make -j2 && make install \
        && cd && rm -rf opencv-3.1.0 && rm 3.1.0.zip

# Build HDF5
RUN cd ; wget https://www.hdfgroup.org/ftp/HDF5/current/src/hdf5-1.8.16.tar.gz
RUN cd ; tar zxf hdf5-1.8.16.tar.gz
RUN cd ; mv hdf5-1.8.16 hdf5-setup
RUN cd ; cd hdf5-setup ; ./configure --prefix=/usr/local/
RUN cd ; cd hdf5-setup ; make && make install

# Cleanup
RUN cd ; rm -rf hdf5-setup
RUN apt-get -yq autoremove
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install Python packages with dependencies on HDF5
RUN pip install tables
RUN pip install h5py
RUN pip install -U scikit-image

RUN rm -fr /root/.cache

# Update environment and working directories
ENV PYTHONUNBUFFERED 1
WORKDIR /app
ADD . /app
RUN mv config ../config

# Setup config
RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf
RUN rm /etc/nginx/sites-enabled/default

RUN ln -s /config/nginx.conf /etc/nginx/sites-enabled/
RUN ln -s /config/supervisor.conf /etc/supervisor/conf.d/

EXPOSE 80
CMD ["python", "app.py"]

Stack Trace

creating build/lib.linux-x86_64-2.7/pandas/tseries/tests/data
    copying pandas/tseries/tests/data/series_daterange0.pickle -> build/lib.linux-x86_64-2.7/pandas/tseries/tests/data
    copying pandas/tseries/tests/data/frame.pickle -> build/lib.linux-x86_64-2.7/pandas/tseries/tests/data
    copying pandas/tseries/tests/data/dateoffset_0_15_2.pickle -> build/lib.linux-x86_64-2.7/pandas/tseries/tests/data
    copying pandas/tseries/tests/data/daterange_073.pickle -> build/lib.linux-x86_64-2.7/pandas/tseries/tests/data
    copying pandas/tseries/tests/data/series.pickle -> build/lib.linux-x86_64-2.7/pandas/tseries/tests/data
    copying pandas/tseries/tests/data/cday-0.14.1.pickle -> build/lib.linux-x86_64-2.7/pandas/tseries/tests/data
    UPDATING build/lib.linux-x86_64-2.7/pandas/_version.py
    set build/lib.linux-x86_64-2.7/pandas/_version.py to '0.18.0'
    running build_ext
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-OD55P2/pandas/setup.py", line 604, in <module>
        **setuptools_kwargs)
      File "/usr/local/lib/python2.7/distutils/core.py", line 151, in setup
        dist.run_commands()
      File "/usr/local/lib/python2.7/distutils/dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/usr/local/lib/python2.7/site-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/usr/local/lib/python2.7/distutils/command/install.py", line 563, in run
        self.run_command('build')
      File "/usr/local/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/usr/local/lib/python2.7/distutils/command/build.py", line 127, in run
        self.run_command(cmd_name)
      File "/usr/local/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/usr/local/lib/python2.7/distutils/command/build_ext.py", line 339, in run
        self.build_extensions()
      File "/tmp/pip-build-OD55P2/pandas/setup.py", line 316, in build_extensions
        self.check_cython_extensions(self.extensions)
      File "/tmp/pip-build-OD55P2/pandas/setup.py", line 313, in check_cython_extensions
        """ % src)
    Exception: Cython-generated file 'pandas/index.c' not found.
                    Cython is required to compile pandas from a development branch.
                    Please install Cython or download a release package of pandas.


    ----------------------------------------
Command "/usr/local/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-OD55P2/pandas/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-JQaDVa-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-OD55P2/pandas/
The command '/bin/sh -c pip install pandas' returned a non-zero code: 1

我不知道你的具体问题,但回答你的一般问题:

Why would the same Dockerfile and docker build command successfully build on one machine, but raise an exception on another?

机器可能使用不同的 python:2.7 图像。许多图像(尤其是官方图像)经常重建,the python tags page 表示 2.7 是 6 天前最后构建的。如果您刚刚创建了 DigitalOcean 实例,它将使用最新的 python:2.7,但如果您在超过 6 天前提取该图像,您将使用过时的图像。如果您 运行 docker pull python:2.7 在您的本地计算机上尝试重建,您应该会得到与在 DigitalOcean 上看到的相同的错误。

另一个相关的可能原因可能是 build caching:如果您的 Docker 文件安装的众多软件包之一最近发生了变化,但您还没有编辑 [= =28=]file 或者它上面的任何行,本地机器上的 Docker 实例在构建时将继续使用旧版本。您可以通过将 --no-cache 选项传递给 docker build.

来关闭本地计算机上构建缓存的使用

Docker 构建在一台机器上成功而在另一台机器上失败的其他可能原因包括使用不同版本的 Docker 或在一台机器和不同代理上下载包时使用 HTTP 代理(或没有代理)在另一个。