G
G
Georgy Kotov2020-03-06 12:09:16
PHP
Georgy Kotov, 2020-03-06 12:09:16

How to install php composer dependencies in Docker from under Jenkins?

Jenkins pulls files from the repository and starts docker compilation.
I have a Docker container with php:7.3-fpm installed like this:
fpm.dockerfile:

FROM php:7.3-fpm

COPY ./server/php.ini /usr/local/etc/php/conf.d/custom.ini

WORKDIR /var/www/project/

# Install dependencies
RUN apt-get update \
    && docker-php-ext-install pdo pdo_mysql

# Install dependencies
RUN apt-get install -y \
    libzip-dev \
    zip \
    unzip \
    git \
    curl

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl

#RUN pecl install -o -f redis \
    #&&  rm -rf /tmp/pear \
    #&&  docker-php-ext-enable redis

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www

# Copy existing application directory contents
COPY ./client/ /var/www/project/
COPY ./client/.env.example /var/www/project/.env

RUN cd /var/www/project/ && composer install --prefer-source --no-interaction


Everything is starting up, dependencies are swinging, the weather is clear in jenkins. But the server returns an error:
Warning: require(/var/www/project/public/../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/project/public/index.php on line 33

Fatal error: require(): Failed opening required '/var/www/project/public/../vendor/autoload.php' (include_path='.:/usr/local/lib/php') in /var/www/project/public/index.php on line 33


Go to the php:7.3-fpm container and see what files are there:
docker exec -ti devtest1_fpm_1 /bin/sh
cd /var/www/project/ && ls -la

drwxr-xr-x 11  111  113   4096 Mar  5 14:10 .
drwxr-xr-x  1 root root   4096 Mar  6 07:58 ..
-rw-r--r--  1  111  113    213 Mar  5 14:10 .editorconfig
-rw-r--r--  1  111  113    726 Mar  5 14:10 .env.example
-rw-r--r--  1  111  113    111 Mar  5 14:10 .gitattributes
-rw-r--r--  1  111  113    163 Mar  5 14:10 .gitignore
-rw-r--r--  1  111  113    174 Mar  5 14:10 .styleci.yml
drwxr-xr-x  6  111  113   4096 Mar  5 14:10 app
-rw-r--r--  1  111  113   1686 Mar  5 14:10 artisan
drwxr-xr-x  3  111  113   4096 Mar  5 14:10 bootstrap
-rw-r--r--  1  111  113   1581 Mar  5 14:10 composer.json
-rw-r--r--  1  111  113 170974 Mar  5 14:10 composer.lock
drwxr-xr-x  2  111  113   4096 Mar  5 14:10 config
drwxr-xr-x  5  111  113   4096 Mar  5 14:10 database
-rw-r--r--  1  111  113 433212 Mar  5 14:10 package-lock.json
-rw-r--r--  1  111  113   1126 Mar  5 14:10 package.json
-rw-r--r--  1  111  113   1156 Mar  5 14:10 phpunit.xml
drwxr-xr-x  4  111  113   4096 Mar  6 06:24 public
-rw-r--r--  1  111  113   4198 Mar  5 14:10 readme.md
drwxr-xr-x  6  111  113   4096 Mar  5 14:10 resources
drwxr-xr-x  2  111  113   4096 Mar  5 14:10 routes
-rw-r--r--  1  111  113    563 Mar  5 14:10 server.php
drwxr-xr-x  5  111  113   4096 Mar  5 14:10 storage
drwxr-xr-x  4  111  113   4096 Mar  5 14:10 tests
-rw-r--r--  1  111  113    538 Mar  5 14:10 webpack.mix.js


But alas, there is no vendor folder. Where are the dependencies installed?

And the files do exist! But they don't get into the docker container!
Step 13/14 : RUN cd /var/www/project/ && composer install --prefer-source --no-interaction
 ---> Using cache
 ---> 4c7460730118
Step 14/14 : RUN find / -name autoload.php
 ---> Running in d5c359699292
/var/www/project/vendor/opis/closure/autoload.php
/var/www/project/vendor/autoload.php
/var/www/project/vendor/fzaninotto/faker/src/autoload.php
Removing intermediate container d5c359699292
 ---> ff3bfdbf7010


PS. just in case.
docker-compose.yml
version: "3.3"

services:
  nginx:
    build:
      context: .
      dockerfile: server/nginx.dockerfile
    ports:
      - 80:80
    links:
      - fpm
    volumes:
      - ./client/:/var/www/project/

  fpm:
    build:
      context: .
      dockerfile: server/fpm.dockerfile
    volumes:
      - ./client/:/var/www/project/
      - ./server/php.ini:/usr/local/etc/php/conf.d/custom.ini
    links:
      - mysql

  mysql:
    image: mysql:5.7
    ports:
      - 33061:3306
    environment:
      - MYSQL_ROOT_PASSWORD=mysql
      - MYSQL_DATABSE=project

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Karasik, 2020-03-06
@agsDevelopment

Add
RUN cd /var/www/project/ && composer install --prefer-source --no-interaction

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question