Dockerfile does not use cache in RUN install command

I thought I already understood Docker, but today I found a problem using the docker cache.

Here is my dockerfile

FROM quay.io/my_company/phpjenkins

WORKDIR /usr/src/my_project
ADD composer.json composer.json
ADD composer.lock composer.lock

RUN composer install -o

ADD . .

RUN mkdir -p temp/unittest/cache log

RUN cp app/config/config.unittest.template.neon app/config/config.unittest.neon

CMD ["tail", "-f", "/dev/null"]

I expect docker to use cache before ADD . .

However, every assembly similar to docker tries to do it composer installevery time.

Here are some weekends

+ docker-compose -f docker-compose.yml run app vendor/bin/phpunit -d memory_limit=2048M
Creating network "xxx_default" with the default driver
Creating xxx_rabbitmq_1
Creating xxx_mysql_1
Building app
Step 1/9 : FROM quay.io/my_company/phpjenkins
 ---> f10ea65fb7df
Step 2/9 : WORKDIR /usr/src/my_project
 ---> Using cache
 ---> 07ad76770cd2
Step 3/9 : ADD composer.json composer.json
 ---> Using cache
 ---> 0d22314b81af
Step 4/9 : ADD composer.lock composer.lock
 ---> Using cache
 ---> 3d41825efcb3
Step 5/9 : RUN composer install -o
 ---> Running in 38de5f08eb46
Warning: This development build of composer is over 60 days old. It is recommended to update it by running "/usr/local/bin/composer self-update" to get the latest version.
Do not run Composer as root/super user! See https://getcomposer.org/root for details ....
...
 ---> aa05dc9ddc5f
Removing intermediate container 581aa7e4b00f
Step 6/9 : ADD . .
 ---> 8796a9235b9a
Removing intermediate container b7354231fbd7

My conclusion is ending, which may be possible if dockerfile did not use the cache for the command RUN composer install

I use Docker version 17.05.0-ce, build 89658bein Debian if this help is for investigation.

Please inform.

+4
source share
1 answer

, Dockerfiles. , , . Dockerfile .

FROM quay.io/my_company/phpjenkins

WORKDIR /usr/src/my_project
ADD composer.json composer.json
ADD composer.lock composer.lock

RUN composer install -o

CMD ["tail", "-f", "/dev/null"]

mycomposerimage,

docker build -t mycomposerimage .

FROM mycomposerimage
WORKDIR /usr/src/my_project
ADD . .

RUN mkdir -p temp/unittest/cache log

RUN cp app/config/config.unittest.template.neon app/config/config.unittest.neon

CMD ["tail", "-f", "/dev/null"]
0

Source: https://habr.com/ru/post/1679732/


All Articles