Skip to content

Composer: /var/www/html/vendor does not exists and could not be created #315

Description

@jaydrogers

Migrated comment

Originally posted by @jsayer101 in #311 (comment)

Hello,
I've started from scratch so see if all my problems were solved, but I found that I had problems using composer.

I got a project with this Dockerfile and this docker-compose.yml :

############################################
# Base Image
############################################
FROM serversideup/php-dev:311-8.2-fpm-nginx-alpine as base

############################################
# Development Image
############################################
FROM base as development

# Switch to root so we can do root things
USER root

# Install the necessary packages for our development environment
RUN apk update && apk add libraw libjpeg
RUN install-php-extensions gd imagick bcmath intl

# Save the build arguments as a variable
ARG USER_ID
ARG GROUP_ID

# Use the build arguments to change the UID
# and GID of www-data while also changing
# the file permissions for NGINX
RUN docker-php-serversideup-set-id www-data $USER_ID:$GROUP_ID && \
    \
    # Update the file permissions for our NGINX service to match the new UID/GID
    docker-php-serversideup-set-file-permissions --owner $USER_ID:$GROUP_ID --service nginx

# Drop back to our unprivileged user
USER www-data

############################################
# Production Image
############################################

# Since we're calling "base", production isn't
# calling any of that permission stuff
FROM base as production

# Switch to root so we can do root things
USER root
RUN apk update && apk add libraw libjpeg
RUN install-php-extensions gd imagick bcmath intl

# Drop back to our unprivileged user
USER www-data

# Copy our app files as www-data (33:33)
COPY --chown=www-data:www-data . /var/www/html
services:
  api:
    build:
      dockerfile: ./Dockerfile
      context: .
      target: development
      args:
        # UID and GID must be set as environment variables on the host machine
        USER_ID: ${UID:-1000}
        GROUP_ID: ${GID:-1000}
    container_name: pix-api
    restart: unless-stopped
    environment:
      PHP_FPM_POOL_NAME: "pixsell_api"
      AUTORUN_ENABLED: "true"
      AUTORUN_LARAVEL_ROUTE_CACHE: "false"
      AUTORUN_LARAVEL_VIEW_CACHE: "false"
      AUTORUN_LARAVEL_CONFIG_CACHE: "false"
      AUTORUN_LARAVEL_EVENT_CACHE: "false"
      PHP_DATE_TIMEZONE: "Europe/Paris"
      PHP_DISPLAY_ERROR: "On"
      PHP_DISPLAY_STARTUP_ERRORS: "On"
      PHP_ERROR_REPORTING: "32767"
      PHP_MEMORY_LIMIT: "4G"
    volumes:
      - .:/var/www/html
    ports:
      - "8000:8080"
    networks:
      - pix-network
    depends_on:
      - db
# .....

Composer got errors while trying to write to vendor/ and it can't install the dependencies. Running composer install in the container get me this error :

var/www/html $ composer install
Composer could not detect the root package (laravel/laravel) version, defaulting to '1.0.0'. See https://getcomposer.org/root-version
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
Package operations: 138 installs, 0 updates, 0 removals

In Filesystem.php line 260:
                                                                 
  /var/www/html/vendor does not exist and could not be created:  
                                                                 

install [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--download-only] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-progress] [--no-install] [--audit] [--audit-format AUDIT-FORMAT] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>...]

Edit : So i've figured out on how to be able to execute composer install inside the container.
I've commented "USER www-data" in the dev stage of the dockerfile, logged in into the container and ran composer install.

I wonder how to implement this automatically using this technique as in the dev stage we don't copy the app as it is mounted using compose 🤔

I tried using entrypoints but I couldn't make it work

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions