仅重建docker中的代码

时间:2018-01-09 14:00:56

标签: docker dockerfile

我有一个非常大的yii2应用程序需要几分钟才能在docker中构建。有没有办法只构建代码,而不是每次“重新安装”所有内容?如何加快dockerized yii2 app的开发/调试?

现在我这样做:

  

docker build -t myapp:mytag。   docker run --name myapp -p 8000:8000 myapp:mytag

我的Dockerfile:

Sub drawEntryArrow()
  Dim x1 As Single, y1 As Single, w As Single, h As Single
  Dim oShape As Shape

  x1 = 10
  y1 = 10

  w = 200
  h = 200

  With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, x1, y1)
   .AddNodes msoSegmentLine, msoEditingAuto, x1 + w, y1
   .AddNodes msoSegmentLine, msoEditingAuto, x1 + w, y1 + h
   .AddNodes msoSegmentLine, msoEditingAuto, x1, y1 + h
   .AddNodes msoSegmentLine, msoEditingAuto, x1 + w / 2, y1 + h / 2
   .AddNodes msoSegmentLine, msoEditingAuto, x1, y1
   Set oShape = .ConvertToShape
  End With

End Sub

1 个答案:

答案 0 :(得分:2)

Docker将重用先前执行且未更改的缓存构建步骤。但是,一旦达到打破缓存的步骤,所有后续步骤都必须重新运行,因为缓存包含对上一步的依赖性。因此,缓存依赖于顺序,您可以将以下内容作为第一步:

COPY . /var/www/html/

每次更改代码时,都必须重新运行该行,然后强制重新运行apt-get行。通过重新安排您的安装,您将看到一个大的加速:

FROM php:5.6-apache

ENV APACHE_DOCUMENT_ROOT /var/www/html/web

RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf

RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

RUN apt-get update && \
    apt-get install -y curl nano unzip zlib1g-dev git && \
    docker-php-ext-install pdo pdo_mysql zip && \
    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# move this line to as late in the build as possible
COPY . /var/www/html/

RUN cd /var/www/html && composer install

RUN cd /var/www/html/ && mkdir web/assets/
RUN chmod 777 /var/www/html/web/assets/

RUN mv /var/www/html/vendor/bower-asset/ /var/www/html/vendor/bower/