在dockerfiles中将哪个Pythonvariables用作基础映像?

我在dockerfile中使用Python_onbuild作为基础镜像,如下所示。 但是,每当我在源文件中进行更改时,都会导致我的命令重复失效。

FROM python:2.7.13-onbuild RUN mkdir -p /usr/src/app WORKDIR /usr/src/app RUN echo "Test Cache" ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install --assume-yes apt-utils RUN apt-get update && apt-get install -y curl RUN apt-get update && apt-get install -y unzip RUN curl -o - url 

构build日志:

 Sending build context to Docker daemon 239.1kB Step 1/6 : FROM python:2.7.13-onbuild # Executing 3 build triggers... Step 1/1 : COPY requirements.txt /usr/src/app/ ---> Using cache Step 1/1 : RUN pip install --no-cache-dir -r requirements.txt ---> Using cache Step 1/1 : COPY . /usr/src/app ---> 13e927036649 

这个复制的第三步(Step 1/1 : COPY . /usr/src/app)使得当我在工作目录中的任何文件中进行更改时,重复其余的命令。 我认为这是从基础图像的ONBUILD命令。 如果那是真的那么在这种情况下替代基础图像是什么? 我应该使用Python吗?

我想要更多地控制需求安装以及复制过程,因为我必须下载一个3.6GB文件,我不想每次构builddocker时都要重复这个文件。

注意:这个特定的基础图像是由其他人select的,我正在build立一些现有的工作之上。

您正在使用的基本映像在此Dockerfile中进行了描述。
正如你所看到的,它基于python:2.7 。 所以,如果你不需要ONBUILD指令,直接使用这个图像或者是一个可以满足你需要的图像:你可以在Docker Hub上的python图像上find一个链接到所有相应Docker文件的链接。

你可以使用基本的Ubuntu的图像和安装Python,或者您可以使用其他图像与Python安装。 您需要在需求安装部分之后移动源复制部分,以便在更改代码时不必执行安装。 这是我的docker文件看起来像。

 ############################################################ # Dockerfile to run a Django-based web application # Based on an Ubuntu Image ############################################################ # Set the base image to use to Ubuntu FROM ubuntu:14.04 ENV DOCKYARD_SRC=app ENV DOCKYARD_SRVHOME=/app # Update the default application repository sources list RUN apt-get update RUN apt-get install -y vim RUN apt-get install -y python-dev RUN apt-get install -y python-pip RUN apt-get install -y build-essential RUN apt-get -y install wget RUN apt-get -y install php5 libapache2-mod-php5 php5-mcrypt RUN apt-get -y install curl libcurl3 libcurl3-dev php5-curl RUN pip install uwsgi RUN mkdir $DOCKYARD_SRC COPY ./requirements.txt $DOCKYARD_SRVHOME/requirements.txt RUN pip install -r $DOCKYARD_SRVHOME/requirements.txt COPY . $DOCKYARD_SRVHOME EXPOSE 8001 8000 WORKDIR $DOCKYARD_SRVHOME RUN chmod +x entrypoint.sh CMD ["./entrypoint.sh"]