composer / docker

Composer in Docker

Home Page:https://hub.docker.com/_/composer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update vendor folder on docker volume for later usage

v-bulynkin opened this issue · comments

I build my PHP image with composer dependencies using multistage Dockerfile:

FROM composer AS vendor
WORKDIR /app

COPY composer.json .
RUN composer install --ignore-platform-reqs --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader

FROM alpine:3.16
WORKDIR /var/www/html

RUN apk add --no-cache \
php8 \
php8-fpm \
php8-mbstring \
php8-pdo_mysql \
php8-exif \
php8-pcntl \
php8-bcmath \
php8-gd \
php8-soap \
php8-zip \
php8-sockets \
php8-session \
php8-fileinfo

RUN \
addgroup -g 82 -S www-data || true && \
adduser -u 82 -D -S -G www-data www-data || true && \
sed -i '/listen = /c listen = 0.0.0.0:9000' /etc/php8/php-fpm.d/www.conf && \
chown -R 82: /var/log/php*

COPY --chown=82:82 --from=vendor /app/vendor ./vendor
COPY --chown=82:82 . .

EXPOSE 9000

USER 82

CMD ["php-fpm8", "-F"]

Works great, but the vendor folder is nearly 90 MB out of 115, which is quite an enormous size for a container.

/var/www/html $ du -shd 1
1.5M    ./resources
2.6M    ./app
16.0K   ./docker-compose
8.0K    ./mysql
20.0K   ./nginx
11.0M   ./storage
28.0K   ./tests
16.0K   ./bootstrap
9.2M    ./.git
156.0K  ./config
1.8M    ./public
340.0K  ./database
32.0K   ./routes
88.4M   ./vendor
115.3M  .

Furthermore, I need to use the same PHP image for listening rabbitmq queues (more than 20) so that'd be great to reduce container's size.
I'd like to mount the vendor folder as volume on host and update files there every time when composer is kicked off.
So, Dockerfile should be splitted up - composer create/update content of the vendor folder on volume and PHP containers just use that volume.
Unfortunately, I can't figure out how to do it.
Is it possible without rsync crutch from $COMPOSER_HOME/vendor to volume?

commented

We do not provide tutorials or guidance on how to use docker / containers.