Home > database >  "composer install" command does not create vendor folder when building docker image
"composer install" command does not create vendor folder when building docker image

Time:01-16

I am trying to run a laraver project in a docker container.

My dockerfile:

FROM php:8.0.12-cli

...
    
# Install composer.
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer --quiet \
    && rm -rf /root/.composer/cache

# Install git.
RUN apt-get update && apt-get install -y git

# Clone laravel project from repo.
RUN git clone https://${USERNAME}:${TOKEN}@github.com/${USERNAME}/api.myproject.com.git

# Copy laravel project to app folder.
RUN cp -r /api.myproject.com/. /app

WORKDIR /app

RUN composer install

Everything seems to be fine, but when I opened the application, I saw an error:

Warning: require(vendor/autoload.php): failed to open stream: No such file or directory

I went into the container and found that the vendor folder was missing, although there were no errors when executing the composer install command and at the end I received a notification that all dependencies were successfully installed.

I don't understand how to fix this, my only guess is that the composer may not have enough permissions to create the vendor directory.

CodePudding user response:

I'm not a docker or Linux pro, but maybe, your working directory should be /app/api.myproject.com.

so you're running cp -r /api.myproject.com/. /app. This will copy the api.myproject.com folder(and it's contents) to /app directory. So that means your composer.json file is in /app/api.myproject.com/

Why don't you give this a try and see what happens :

WORKDIR /app/api.myproject.com

RUN composer install

CodePudding user response:

I had the same problem, but funnily enough only in Windows. I think either https://stackoverflow.com/a/46792094/4613879 or https://stackoverflow.com/a/64684355/4613879 answered my question.

However the first one seems like a hacky solution, it will look like the container is ready, however if you inspect it you will see it is still running composer install for a while, but after it is done, it should work.

  •  Tags:  
  • Related