0

I am using php FPM alpine container with nginx alpine container for my laravel application.

Here is my Dockerfile,

FROM php:7.4-fpm-alpine
WORKDIR /usr/src/app

# install composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN php -r "unlink('composer-setup.php');"

# copy files
COPY ./ /usr/src/app/

# install packages
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN composer install

Here is my docker-compose file,

version: "3.7"
services:
  web:
    image: nginx:1.19-alpine
    ports:
      - 80:80
    volumes:
      - ../api:/usr/src/app
      - ./site.conf:/etc/nginx/conf.d/site.conf
    depends_on:
      - api

  api:
    build: ../api
    volumes:
      - ../api:/usr/src/app

When I run docker-compose up --build the container build process works as you can see in the attached screenshot but the vendor directory was never created by the composer!?

enter image description here

Is it a known issue while using PHP FPM Alpine containers?

Also, when I access into the container using this command

docker exec -it docker_api_1 /bin/ash

and run composer install manually then everything works. Any suggestions are appreciated.

This is the error message when i visit the site. It can't find the composer autoload.php file, enter image description here

rakibtg
  • 5,521
  • 11
  • 50
  • 73
  • 2
    This happens because you are, at run time, removing everything that was done by composer by mounting your host folder back over */usr/src/app* – β.εηοιτ.βε Jan 02 '21 at 21:54
  • You have to run `composer install` in an entrypoint. – β.εηοιτ.βε Jan 02 '21 at 21:55
  • Related: https://stackoverflow.com/questions/52185927/composer-install-with-dockerfile – β.εηοιτ.βε Jan 02 '21 at 21:57
  • @β.εηοιτ.βε Thanks for the help! I just removed the volume mount from api service, but now it shows permission error: `file_put_contents(/usr/src/app/storage/framework/sessions/qyNi95ds9AT6cCM3l5sZyS): failed to open stream: Permission denied` – rakibtg Jan 02 '21 at 22:00
  • `it shows permission error` => did you check the permissions ? what are they ? What have you tried to debug/fix that ? – Zeitounator Jan 02 '21 at 22:19

0 Answers0