-2

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.

jixiva6012
  • 11
  • 1
  • 3
  • cloning to a directory and then `cp -rp`ing everything to a _different_ directory seems a waste of time at best. That being said, the above is not enough to see why the directory would be missing. The Dockerfile above **should** create a vendor director within the built image. Some important detail is missing. – yivi Jan 15 '22 at 15:15
  • You can't use a `RUN` composer install. The folder will be erased when your volumes will be mounted. You have to run `composer install` in entrypoint. – John Feb 21 '22 at 13:49

1 Answers1

-1

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