I asked a question few days ago about preparing a laravel project in Docker with postgresql
(https://laracasts.com/discuss/channels/laravel/docker-laravelpostgresql-translation-to-hostname)
Everything worked well (thanks to the answer I get).
The yaml file is this one:
version: '3'
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- database
database:
build:
context: ./postgresql
dockerfile: Dockerfile.db
container_name: postgresql
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_USER=XXXX
- POSTGRES_PASSWORD=XXXX
- POSTGRES_DB=XXXX
restart: always
tty: true
ports:
- "5433:5432"
php:
build:
context: ./php
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
Now that everything is working i thought about using GitHub to make some tests and change only the project section.
My .gitignore is like this one:
src/vendor
src/node_modules
src/public/storage
src/Homestead.yaml
src/Homestead.json
src/.env
Now when i pull the repo and do "docker-compose up -d --build", I get internal server error.
Checking the logs I discovered that the vendor/autoload.php (and probably all the vendor files) is not present.
So i thought about running "composer install".
Now, my problem is that I don't know where and how to set that command.
Nginx starts only after php and postgresql has started.
So where should i put the
RUN composer install
?? I tried inside the Dockerfile of the php
FROM php:7.2-fpm
RUN apt-get update && apt-get install -y libpq-dev
RUN docker-php-ext-install pdo pdo_pgsql pgsql
RUN ln -s /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
RUN sed -i -e 's/;extension=pgsql/extension=pgsql/' /usr/local/etc/php/php.ini
RUN sed -i -e 's/;extension=pdo_pgsql/extension=pdo_pgsql/' /usr/local/etc/php/php.ini
RUN apt-get install -y nodejs npm
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN composer install
RUN npm install
but I get the error becasue it says it doesn't found var/www/html/composer.json.
So I thought that maybe I should run the composer command after nginx (the last container to start) has started.
Is there a way to achieve this?