Why is vendor directory empty in PHP/Symfony project running inside Docker container

In my Docker/docker-compose based Symfony project I have the following directory structure:

.
├── docker-compose.yml
└── server
    ├── app
    │   ├── .bash_history
    │   ├── bin
    │   ├── .composer
    │   ├── composer.json
    │   ├── composer.lock
    │   ├── config
    │   ├── .dockerignore
    │   ├── .env
    │   ├── .env.local
    │   ├── .env.test
    │   ├── .gitignore
    │   ├── phpunit.xml.dist
    │   ├── public
    │   ├── README.md
    │   ├── src
    │   ├── symfony.lock
    │   ├── templates
    │   ├── tests
    │   ├── translations
    │   ├── uploads
    │   ├── var
    │   └── vendor
    ├── .bash_history
    ├── .composer
    ├── Dockerfile
    └── .env.dev.local

My docker-compose.yml looks like:

version: '3'

services:
  php:
    build:
      context: server
      args:
        - USER_ID=1000
    ports:
      - 8001:8000
    volumes:
      - ./server/app:/var/www
      - composerCache:/var/www/.composer
      - composerVendor:/var/www/vendor
volumes:
  composerCache:
  composerVendor:

And here is the Dockerfile:

FROM php:7.3.16-cli-buster

RUN apt-get update && apt-get install -y --no-install-recommends libbz2-dev libenchant-dev libpng-dev libldap2-dev libgmp-dev libc-client-dev libkrb5-dev libicu-dev 
    libmcrypt-dev libxml2-dev libmagickwand-dev libzip-dev

RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && 
    docker-php-ext-configure imap --with-kerberos --with-imap-ssl && 
    docker-php-ext-install ldap mysqli pdo_mysql bcmath bz2 calendar exif zip intl gmp soap gd dom imap sockets

RUN pecl install imagick xdebug-2.9.0 && docker-php-ext-enable imagick xdebug

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY ./app .

# Copy Symfony .env.local override
COPY .env.dev.local .

RUN composer install

ARG USER_ID=1000
# Switch local user to be www-data user
RUN usermod -u ${USER_ID} www-data && groupmod -g ${USER_ID} www-data

WORKDIR /var/www

RUN chown -R www-data:www-data /var/www

USER www-data

CMD ["php", "bin/console", "server:run", "*:8000"]

After building image and running docker-compose up -d I get the following error:

php_1  | Warning: require(/var/www/vendor/autoload.php): failed to open stream: No such file or directory in /var/www/bin/console on line 11

I ran docker-compose run php bash to inspect the container and confirmed that the vendor director is empty and owned by root.

The volume composerVendor:/var/www/vendor is meant to keep the vendor directory from being overwritten by the outer bind mount. For some reason instead it is empty.

I have a nearly identical setup with a Node container with the node_modules directory and in that case it works perfectly.

Any ideas?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *