How to cache package manager downloads for docker builds?

If I run composer installfrom my host, I get into the local composer cache:

  - Installing deft/iso3166-utility (1.0.0)
    Loading from cache

However, when creating a container that has in its Dockerfile:

RUN composer install -n -o --no-dev

I load all things, for example:

  - Installing deft/iso3166-utility (1.0.0)
    Downloading: 100%         

It was expected, but I would like to avoid it. As with recovery, it will also download everything again.

I would like to have a universal cache for the composer, which I could also use for other docker projects.

I studied this and found an approach for defining a volume in a Dockerfile :

ENV COMPOSER_HOME=/var/composer
VOLUME /var/composer

I added this to my Dockerfileand expected that the files will be downloaded only once, and then it will go to the cache.

, -o composer, -o -o docker build. , .

, -?

+5
2

, .

  • : hirak/prestissimo

    composer global require "hirak/prestissimo:^0.3"
    
  • .
    RUN, . COPY . /your-php-app, docker build , .
    , , composer.json composer.lock. , rsync ; , .
    (untested):

    WORKDIR /tmp/
    COPY composer.json composer.lock ./
    RUN composer install -n -o --no-dev --no-scripts
    
    WORKDIR /your-php-app/ 
    COPY . /your-php-app/
    RUN rsync -ah /tmp/* /your/php-app/
    RUN composer run-script post-install-cmd
    

=)

+1

$HOME/.composer/cache/files. , composer / composer install.

, . composer install run composer install composer install composer install.

, Travis CI .

--prefer-dist composer install.

: https://getcomposer.org/doc/03-cli.md#install

--prefer-dist: --prefer-source, dist, . , . git, .

:

0

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


All Articles