0

I'm running my application in Docker Windows wsl/Ubuntu, using PHP 8.1. Docker looks into my working directory, not in the root directory to get the autoloader. However, the vendor folder is in the root directory of my project.

FROM php:latest

RUN groupadd -r appgroup && useradd -r -g appgroup appuser

RUN apt-get update && apt-get install -y libcurl4-gnutls-dev

RUN docker-php-ext-install mysqli pdo pdo_mysql curl

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

WORKDIR /var/www/html

COPY . /var/www/html

RUN chown -R appuser:appgroup /var/www/html

USER appuser

RUN composer install

VOLUME /var/www/html/

EXPOSE 80

CMD ["php", "-S", "0.0.0.0:80"]


my index.php (located in the working directory):

require_once __DIR__ . '/../vendor/autoload.php';

echo 'test';

the result I get in my browser: Warning: require_once(/var/www/html/../vendor/autoload.php): Failed to open stream: No such file or directory in /var/www/html/index.php on line 3

Fatal error: Uncaught Error: Failed opening required '/var/www/html/../vendor/autoload.php' (include_path='.:/usr/local/lib/php') in /var/www/html/index.php:3 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 3

How Do I configure my Dockerfile to not search for the vendor folder in my src aka working folder?

Kavalants
  • 1
  • 1
  • "Docker looks into my working directory" - Docker itself won't do that. What have you tried to resolve the problem? How is this related to Composer itself, or WSL2? – Nico Haase Aug 03 '23 at 09:59

1 Answers1

0

You might find the answer on PHP - Failed to open stream : No such file or directory You need to set SITE_ROOT which is missing in your index.php

With this method; it doesn't depend on ini settings of php and simplifies the deployment in docker if you need to scale it further down the line.

  • Got this error: Fatal error: Uncaught Error: Undefined constant "SITE_ROOT" in /var/www/html/index.php:2 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 2 – Kavalants Aug 03 '23 at 07:04