Composer memory limit docker

10,577

Solution 1

Composer has its own COMPOSER_MEMORY_LIMIT environment variable, but uses php.ini's memory_limit by default when its own variable is not set. https://getcomposer.org/doc/03-cli.md#composer-memory-limit

With Docker Compose you will need to pass COMPOSER_MEMORY_LIMIT as an environment variable to the container where Composer is installed. Your docker-compose.yml file would look like this:

services:

  php-fmp: //the name of your container (as per your question)

    environment:
      - COMPOSER_MEMORY_LIMIT=-1 //-1 means unlimited

This environment variable would be taken into account every time you run Composer with docker-compose:

docker-compose exec php-fmp composer [your composer command]

Solution 2

Instead of php -d memory_limit=-1 composer install try COMPOSER_MEMORY_LIMIT=-1 composer install. Composer starts a new php process, that does not adhere to the setting you provide and it might even override the config (I'm not a 100% sure about that).

If that still does not help open the preferences for Docker (by clicking on the icon in the task bar) under the Advanced tab you can specify how many cores and how much memory docker is allowed to consume. I think the default is 2GB and you might want to change that to e.g. 4GB.

Share:
10,577
SharkCode
Author by

SharkCode

Updated on June 20, 2022

Comments

  • SharkCode
    SharkCode almost 2 years

    I have a problem with composer install on docker. This is my docker-compose file:

    version: '3'
    services:
    
      webserver:
        image: nginx:latest
        ports:
          - 80:80
          - 433:433
        volumes:
          - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
          - ./:/var/www/html/
        links:
          - php-fmp
          - db
        networks:
          - app-network
    
      php-fmp:
        build: docker/php-fmp
        volumes:
          - ./:/var/www/html/
        ports:
          - 9000:9000
        links:
          - db
        networks:
          - app-network
    
      db:
        image: mysql
        ports:
          - 3306:3306
        volumes:
          - /var/lib/mysql
        command: --default-authentication-plugin=mysql_native_password
        restart: always
        environment:
          - MYSQL_DATABASE=goexpress
          - MYSQL_USER=root
          - MYSQL_PASSWORD=root
          - MYSQL_ROOT_PASSWORD=docker
        networks:
          - app-network
    
    networks:
      app-network:
        driver: bridge
    

    I try to execute docker-compose run php-fmp composer install it starts after some minutes it shows memory limit xxxxxxxxx. I have tried also memory_limit=-1.

    My laptop memory: 6GB.

    In another pc it works perfect.

    Before upgrade of memory it has worked. Memory before was 4GB now it is 6GB. The project that I want to run is symfony.