Docker镜像build立在笔记本电脑上,而不是数字海洋 – 我对Docker的理解已经破灭
对于我正在构build的Python应用程序,我有一个非平凡的Docker
环境(请参阅下面的完整Dockerfile
)。 在我的MacBook上( Docker version 1.10.3, build 20f81dd
)我可以构buildDocker
镜像,运行容器,应用程序正常工作。
我现在想testing数字海洋上的应用程序。 到目前为止,我在笔记本电脑上只使用过Docker。 我使用Ubuntu Docker 1.10.3 on 14.04
镜像Ubuntu Docker 1.10.3 on 14.04
的Ubuntu Docker 1.10.3 on 14.04
创build了一个小滴。 我在SSH中,克隆了我的git repo,执行了docker build
命令,但是在构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.
这是一个有效的exception,但我的问题是: 为什么相同的Dockerfile
和Dockerfile
docker build
命令在一台机器上成功构build,但在另一台机器上引发exception? 我对Docker的理解是,它通过使用Dockerfile从头开始构build环境,防止了这种事情的发生……我只是无法围绕在一台机器上导致此exception而不是在另一台机器上造成这种情况。
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
我不知道你的具体问题,但要回答你的一般问题:
为什么同一个Dockerfile和docker build命令会在一台机器上成功构build,但在另一台机器上引发exception?
这很可能是机器使用不同的python:2.7
图像。 许多图片(特别是官方图片)经常被重build, python
标签页说2.7
是最近6天前build立的。 如果你刚刚创build了DigitalOcean实例,它将使用最新的python:2.7
,但是如果你在六天前拉动了这个图像,你将会使用一个过时的图像。 如果在本地机器上运行docker pull python:2.7
并尝试重build,则应该会看到DigitalOcean上出现的相同错误。
另一个可能的相关原因可能是构buildcaching :如果Dockerfile安装的许多软件包中的一个最近已经更改,但是您最近没有编辑Dockerfile的那一行或上面的任何行,那么本地的Docker实例机器在build造时会继续使用旧版本。 您可以通过将--no-cache
选项传递给docker build
来closures本地机器上构buildcaching的使用。
Docker构build在一台机器上成功并在另一台机器上失败的其他可能的原因包括在一台机器上下载软件包时使用不同版本的Docker或使用HTTP代理,而在另一台机器上下载不同代理(或无代理)。