I have a Laravel Project and I created a docker-compose and dockerfile.
I do docker-compose build and my problem is that:
- It does not create the folder vendor (composer install).
- Do not copy .env.local to .env
- Do not create the node_modules folder
docker-compose.yml
version: "3"
services:
api:
container_name: nadal_api
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/var/www/html/app
ports:
- 5002:80
DockerFile
FROM composer:latest AS composer
#Generamos el primer build desde un container de nodejs
FROM node:latest as nodebuild
COPY --chown=root:www-data . /var/www/html/app
WORKDIR /var/www/html/app
RUN npm install
RUN npm run production
#Tomamos la imagen de php fpm para utilizar las librerias compiladas
FROM php:7.2-fpm-stretch
#Instalamos nginx y otras dependencias del framework
RUN apt-get update && apt-get install -y \
apt-transport-https \
wget \
lsb-release \
libxml2-dev \
nginx \
ca-certificates \
git \
zip
#Compilamos pgsql
RUN apt-get install -y libpq-dev \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo pdo_pgsql pgsql
#Compilamos las librerias requeridas por laravel
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install xml
RUN docker-php-ext-install mbstring
#Install supervisor porque debemos tener dos procesos, nginx y fpm
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
RUN apt-get update && apt-get install -y \
supervisor \
curl \
libssl-dev \
libmcrypt-dev
#Copiamos las configuraciones de nginx, el host y supervisor
ADD docker/nginx.conf /etc/nginx/nginx.conf
ADD docker/virtualhost.conf /etc/nginx/conf.d/default.conf
ADD docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
#Copiamos el projecto con los modulos de node y los assets compilados
COPY --from=nodebuild --chown=root:www-data /var/www/html/app /var/www/html/app
COPY --chown=root:www-data ./.env.local /var/www/html/app/.env
#Aplicamos los permisos que corresponden
RUN chmod -R g+w /var/www/html/app/storage
RUN chmod -R g+w /var/www/html/app/bootstrap
#Copiamos composer
COPY --from=composer /usr/bin/composer /usr/bin/composer
##Download composer packages
WORKDIR /var/www/html/app
RUN composer install
RUN chmod -R g+w /var/www/html/app/vendor
RUN php artisan key:generate
EXPOSE 80
CMD ["/usr/bin/supervisord"]
Can it be the permissions?
Step 21/30 : COPY --chown=root:www-data ./.env.${environment:-local} /var/www/html/app/.env ---> 7d1038fe2615
Step 26/30 : RUN composer install ---> Running in 8e3265277308
Removing intermediate container 8e3265277308 ---> 429553e893a4 Step 27/30 :
RUN chmod -R g+w /var/www/html/app/vendor ---> Running in 9e276059478b Removing intermediate container 9e276059478b ---> d52ee5ad4ec4
volumes:
declaration is hiding the interesting work that's happening in the Dockerfile. If you want to see the/var/www/html/app/vendor
from the image, you can't mount content over/var/www/html
. – David Mazegit
to run. Prefer running nginx in a separate container, and then you don't need supervisord. – David Mazeservice
you define in yourdocker-compose.yml
will generate an own container. You can define as many services in there as you want and thus reach better isolation between your applications, for example running a webserver (e.g. as reverse proxy) in a separate container is a common thing to do. – bellackn