We came across a problem related Symfony4 and Dockerfile. The error is : while building ,in dockerfile, composer install and clear-cache and dump-autoload commands are executed , afterwards composer run-scripts run 'post-install-cmd' , post-install-cmd is set run auto-scripts in composer.json . Error is thrown while bin/console cache:clear is executing.
The real problem is at COPY . ./ , this docker COPY command copy all of current folder content to /srv/api in docker. But, that copying overwrites existing files in the container so "vendor" directory is overwriten. Due to overwriten vendor folder, symfony cannot find the installed composer packages (e.g. swiftmailer), already that packages is installed before 2-3 commands.
We solve that by excluding /vendor folder in .dockerignore file.
** //.dockerignores
vendor/* **
Code sight:
/*
ARG APP_ENV=prod
# prevent the reinstallation of vendors at every changes in the source code
COPY composer.json composer.lock ./
# do not use .env files in production
RUN echo '<?php return [];' > .env.local.php
RUN set -eux; \
composer install --prefer-dist --no-autoloader --no-scripts --no-progress --no-suggest; \
composer clear-cache
COPY . ./ --- here is real problem , i will tell
# COPY ./docker.env ./.env
RUN set -eux; \
mkdir -p var/cache var/log; \
mkdir -p /symfony/var/cache symfony/var/log symfony/vendor; \
composer dump-autoload --classmap-authoritative; \
composer run-script post-install-cmd; \
*/