docker icon indicating copy to clipboard operation
docker copied to clipboard

Allowed memory size of xxx bytes exhausted in container

Open KoMa1012 opened this issue 4 years ago • 8 comments

Hey Guys,

I'm trying to use the face recognition app in nextcloud using the nextcloud container from iamklaus using unraid as a host. As soon I run (within the container):

# sudo -u www-data php occ face:background_job -t 60 

I'm getting the error:

Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 446464 bytes) in /var/www/html/3rdparty/composer/autoload_real.php on line 37

I've set an environmental variable "PHP_MEMORY_LIMIT" to 2048MB, I double checked this in the settings under System, it shows PHP has a memory Limit of 2GB.

I used the commands @SuperSandro2000 suggested in his post which didn't help. I tried some other things (manually editing the php.ini files loocing for apcu config...) which also didn't help.

On stackoverflow I found a suggestion from Amitesh Kumar to edit the file /var/www/html/3rdparty/composer/autoload_real.php and add ini_set('memory_limit', '-1'); before the line where it is failing. This helped, unfortunately this is only a temporary solution, the edit is gone as soon there is an update for the container or for this specific file when doing a nextcloud update.

KoMa1012 avatar Dec 02 '21 16:12 KoMa1012

Had the same Problem. This was not an issue in the privious release.

Relatet suggestions:

Fix it with apc.enable_cli=1 (see here)

Use the above solution from KoMa1012 if you are (like me or others) to stupid to find the "/etc/php/8.0/cli/conf.d/20-apcu.ini" file.

Would be nice if that could be fixed. Thanks in advance

tstreibl avatar Dec 03 '21 14:12 tstreibl

Thank you for the idea, I thought of that already. It seems to me, that the container already has this set. It's in the file: /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini

However, what I just noticed, I ran php -i | grep 'Configuration File' and I get the output: Configuration File (php.ini) Path => /usr/local/etc/php Loaded Configuration File => (none) This directory only contains 2 files called php.ini-development and php.ini-production plus the folder conf.d where all the other php config files are stored. Could this be related to the issue?

KoMa1012 avatar Dec 03 '21 20:12 KoMa1012

Sorry, but I can't help you on this issue. I'm not a skilled unix user. Nice that you found a file where the apc.enable_cli=1 obviously is set correctly. So I don't understand why I'ts not working. But I guess it's easy to fix for the creators of this container.

As a temporary solution I managed to run my occ commands for example with

sudo -u www-data php -d memory_limit=-1 /var/www/html/occ db:add-missing-indices

after installing sudo inside the container. That's the solution I found on the cited links.

tstreibl avatar Dec 03 '21 22:12 tstreibl

I already created a bug report against the container, but the creator said it’s a nextcloud issue since it’s not related to his container since it’s working for him and other people. Which I find weird, but I also think there is something off with nextcloud.

KoMa1012 avatar Dec 04 '21 13:12 KoMa1012

I have the same issue with the official container (https://hub.docker.com/_/nextcloud) which is build out of this repository as far as I know.

I set the PHP_MEMORY_LIMIT to 1G which should be enough, at least it works fine if I use it directly as PHP parameter while calling occ.

Also it seems like the variable is read correctly:

php -i | grep -i memory
Zend Memory Manager => enabled
memory_limit => 1G => 1G
Collecting memory statistics => No
opcache.memory_consumption => 128 => 128
opcache.preferred_memory_model => no value => no value
opcache.protect_memory => Off => Off
PHP_MEMORY_LIMIT => 1G
$_SERVER['PHP_MEMORY_LIMIT'] => 1G
$_ENV['PHP_MEMORY_LIMIT'] => 1G

Still if I run occ without any special parameter I get the same error:

Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 442368 bytes) in /var/www/html/3rdparty/composer/autoload_real.php on line 35

Maybe @szaimen or @jbcortezf has a idea?

schiessle avatar Aug 21 '22 10:08 schiessle

Here are my dockerfiles on case this helps to reproduce and fix it: https://codeberg.org/bjoern/nextcloud-docker

schiessle avatar Aug 22 '22 14:08 schiessle

hm... the docker-compose file looks good to me. No idea why this happens to you...

szaimen avatar Aug 22 '22 14:08 szaimen

as a workaround, I'm switching to the user www-data su www-data -s /bin/bash then I can start occ with ./occ

kangaroo72 avatar Sep 09 '22 13:09 kangaroo72

I found the problem. @schiessle you need to run the occ file like this: sudo -E -u www-data php occ

szaimen avatar Oct 27 '22 14:10 szaimen