Home > Mobile >  How to map composer vendor folder to docker volume ? (case of Symfony bundle linked to my projet)
How to map composer vendor folder to docker volume ? (case of Symfony bundle linked to my projet)

Time:12-21

I am stuck with that problem.

I have a docker compose file with volumes mapping that way :

 volumes:
  - ./:/var/www/html:rw
  - ../epossobundle/:/var/www/epossobundle :rw;

In composer.json, there is a repo linked on a bundle which I am working on it like this :

  "repositories": [
{
  "type": "path",
  "url": "../epossobundle"
},

But when I start my container I got the error

Warning: include(/var/www/html/vendor/composer/../epo/api-auth-sso-bundle/EpoApiAuthSsoBundle.php): failed to open stream: No such file or directory

How can I do ??

PS : It is not possible to install something in Docker image because it is intranet network

Thanks a lot Serge

CodePudding user response:

I assume that the vendor file is missing dependencies, specifically epo/api-auth-sso-bundle/EpoApiAuthSsoBundle.php so you'll need to install them.

Grab a root shell inside the container:

docker exec -it -u root <container_id_or_name> /bin/bash

Install composer (requires root):

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

Then install your dependencies (if not in production, no need for --no-dev):

composer install --no-dev

Finally, change the permissions back (ls -rvla):

# Nginx
chown -R nginx:nginx .
# Apache2
chown -R www-data:www-data .

Note: This is a "hacky-fix", if you rebuild the container you will have to do this every time. You should look to do this inside your Dockerfile as a permanent solution.

Untested example of the Dockerfile:

FROM php:7.4-fpm
WORKDIR /var/www/html

# Nginx
RUN groupadd -g 101 nginx && \
    useradd -u 101 -ms /bin/bash -g nginx nginx

# Apache2
RUN groupadd -g 101 www-data && \
    useradd -u 101 -ms /bin/bash -g www-data www-data

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

# Nginx
USER nginx
# Apache2
USER www-data

# Or add this as an entry-point (runs as user for permissions)
RUN composer install --no-dev

CodePudding user response:

Thanks but it is not possible to install composer inside container. We cannot install anything anyway.

The vendor folder is in "/var/www/html", it is ok for that.

Inside vendor I have a subfolder "epo" with a logical link : api-auth-sso-bundle -> ../../../epossobundle

I saw a typo error on my docker volumes, I've corrected :

- ../epossobundle/:/var/www/epossobundle/:rw

Now inside html/vendor I have a logical link :

root@677b4bd141aa:/var/www/html/vendor/epo# ls -l

lrwxrwxrwx 1 1000 1000 21 Dec 20 14:21 api-auth-sso-bundle -> ../../../epossobundle

But it is still not working.

/var/www/epossobundle is empty !

  • Related