1

Description

I'm deploying my symfony project in prod. It works fine when I simply run docker-compose up. However I'm getting an issue with my deploy script and try accessing the web page in my navigator.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /var/www/redaph/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65536 bytes) in /var/www/redaph/vendor/composer/ClassLoader.php on line 444

What is weird is that, in my dockerfile I specify that I want my PHP_MEMORY_LIMIT to be at 256M. When I enter my container I see the following:

root@125de315edca:/var/www/redaph# php -i | grep memory_limit
memory_limit => 128M => 128M

Question

Why is my Docker Symfony project consuming so much memory?

If this is normal then: How do I correctly increase the PHP_MEMORY_LIMIT in my dockerfile?

deploy_prod.sh

#!/usr/bin/env bash
PROJECT=symfony
docker-compose up -d
docker exec redaph_symfony_1 php bin/console d:s:u --force
docker exec redaph_symfony_1 php bin/console c:c

Dockerfile:

FROM php:7.2-apache

ENV \
    APACHE_ADMIN_EMAIL=webmaster@localhost \
    PHP_TIME_ZONE=Europe/London \
    PHP_MEMORY_LIMIT=256M \
    PHP_UPLOAD_MAX_FILESIZE=32M \
    PHP_POST_MAX_SIZE=32M

ARG WORK_DIR

WORKDIR $WORK_DIR

COPY composer.lock $WORK_DIR
COPY composer.json $WORK_DIR

ENV COMPOSER_ALLOW_SUPERUSER 1

RUN apt-get update \
    && apt-get install -y -f apt-transport-https \
        libicu-dev \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
        libpq-dev \
        acl \
        cron \
        git \
        zip \
    && pecl install mongodb \
    && docker-php-ext-enable mongodb \
    && docker-php-ext-install \
        exif \
        gd \
        intl \
        opcache \
        pdo_mysql \
        pdo_pgsql \
        zip \
    && curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/local/bin/composer \
    && composer install --no-dev --prefer-dist --optimize-autoloader --no-scripts \
    && chown -R www-data:www-data $WORK_DIR \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    && a2enmod rewrite \
    && service cron start
  • Did you ever figure it out? – Callistino Mar 20 '19 at 18:16
  • @Callistino yes and no. It's a project I'm still working on and I'm going to have to fix this issue soon. However, I believe it's an issue with my docker file. I had a talk with someone who is a pro and it's most likely something to do the complexity of the dickerfile – kemicofa ghost Mar 20 '19 at 18:22

1 Answers1

2

It's most likely that your docker image lacks writing permissions for folder where logs are stored which causes monolog to run out of memory (loops of errors).

Solution: Change permissions of the logs folder, or get info about "buffer_size":https://symfony.com/doc/2.0/reference/configuration/monolog.html (not sure if this will work with all handlers)

Intol
  • 21
  • 2