In my case, my Dockerfile contained an installation step, which produced the vendor
directory (the PHP equivalent of node_modules
). I then COPY
this directory over to the final application image. Therefore, I could not put vendor
in my .dockerignore
. My solution was simply to delete the directory before performing composer install
(the PHP equivalent of npm install
).
FROM composer AS composer
WORKDIR /app
COPY . .
RUN rm -rf vendor \
&& composer install
FROM richarvey/nginx-php-fpm
WORKDIR /var/www/html
COPY --from=composer /app .
This solution works and does not bloat the final image, but it is not ideal, because the vendor
directory on the host is copied into the Docker context during the build process, which adds time.