Laravel Docker – Composer can’t create vendor folder

  composer-php, digital-ocean, docker, docker-compose, laravel

I have been using this pre-made docker-compose-laravel Setup for my website https://github.com/aschmelyun/docker-compose-laravel.

After installing my local dev environment and adding the logic i tried deploying the project via DigitalOcean’s Droplet service.

When running the command to install composer

docker-compose run --rm composer install

i get the following common error message

/var/www/html/vendor/doctrine does not exist and could not be created.

The docker-compose.yml’s nginx-container should create the required www folders and all necceassary subfolders however after successfully bringing up all containers via

docker-compose up -d --build

my Droplet still does not have a /www folder and therefore cannot access or write into the required folders.

Docker-compose.yml:

services:
  site:
    build:
      context: .
      dockerfile: nginx.dockerfile
      args:
        - NGINXUSER=${NGINXUSER:-www-data}
        - NGINXGROUP=${NGINXGROUP:-www-data}
    container_name: nginx
    ports:
      - 80:80
    volumes:
      - ./src:/var/www/html:delegated
    depends_on:
      - php
      - redis
      - mysql
      - mailhog
    networks:
      - laravel

...

php:
    build:
      context: .
      dockerfile: php.dockerfile
      args:
        - PHPUSER=${PHPUSER:-www-data}
        - PHPGROUP=${PHPGROUP:-www-data}
    container_name: php
    volumes:
      - ./src:/var/www/html:delegated
    networks:
      - laravel

nginx.dockerfile:

FROM nginx:stable-alpine

ARG NGINXGROUP
ARG NGINXUSER

ENV NGINXGROUP=${NGINXGROUP}
ENV NGINXUSER=${NGINXUSER}

RUN sed -i "s/user www-data/user ${NGINXUSER}/g" /etc/nginx/nginx.conf

ADD ./nginx/default.conf /etc/nginx/conf.d/

RUN mkdir -p /var/www/html

RUN adduser -g ${NGINXGROUP} -s /bin/sh -D ${NGINXUSER}; exit 0

php.dockerfile:

FROM php:7.4-fpm-alpine

ARG PHPGROUP
ARG PHPUSER

ENV PHPGROUP=${PHPGROUP}
ENV PHPUSER=${PHPUSER}

RUN adduser -g ${PHPGROUP} -s /bin/sh -D ${PHPUSER}; exit 0

RUN mkdir -p /var/www/html

WORKDIR /var/www/html

RUN sed -i "s/user = www-data/user = ${PHPUSER}/g" /usr/local/etc/php-fpm.d/www.conf
RUN sed -i "s/group = www-data/group = ${PHPGROUP}/g" /usr/local/etc/php-fpm.d/www.conf

RUN docker-php-ext-install pdo pdo_mysql

RUN mkdir -p /usr/src/php/ext/redis 
    && curl -L https://github.com/phpredis/phpredis/archive/5.3.4.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 
    && echo 'redis' >> /usr/src/php-available-exts 
    && docker-php-ext-install redis

CMD ["php-fpm", "-y", "/usr/local/etc/php-fpm.conf", "-R"]

Source: Docker Questions

LEAVE A COMMENT