5
votes

I am having problems with docker-compose getting php-fpm container up with composer install.

I have folder structure like:

docker-compose.yml
containers/
    nginx
        Dockerfile
    php-fpm
        Dockerfile

docker-compose.yml:

version: '3'

services:
    nginx:
        build:
            context: ./containers/nginx
        ports:
            - 80:80
    php-fpm:
        build:
            context: ./containers/php-fpm
        tty: true

and in php-fpm/Dockerfile:

FROM php:7.1.5-fpm-alpine

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

WORKDIR /srv/www

ENTRYPOINT composer install --prefer-source --no-interaction --no-autoloader

With current ENTRYPOINT, it seems that composer install gets stuck at "Generating autoload files", because nothing after that is outputted and container does not appear in docker ps list.

How can I keep above folder structure, but still able to run composer install after build or run (in this case I would need to add if conditions)?

1

1 Answers

-1
votes

The problem is that you need a composer.json.

Please, follow these steps:

  1. Go to Get composer web -> getting started and create a composer.json file.
  2. Put this composer.json file in your dir structure as follows, for example:

    • docker-compose.yml
    • containers/
      • nginx
        • Dockerfile
      • php-fpm
        • Dockerfile
    • composer/
      • composer.json
  3. Mount volume (modifying your docker-compose.yml file) to share composer.json to /var/www/html in php-fpm docker, because although you specify /srv/www/ as workdir, composer looks up in /var/www/html.

    version: '3'

    services:
        nginx:
            build:
                context: ./containers/nginx
            ports:
                - "80:80"
        php-fpm:
            build:
                context: ./containers/php-fpm
            tty: true
            volumes:
                - ./composer/composer.json:/var/www/html/composer.json

I hope it's useful for you.