Memory limit too low, but only in CLI

Nextcloud version: 21.0.0
Operating system and version: Official Nextcloud Docker Image 21.0.0-fpm
Apache or nginx version: nginx/1.19.8
PHP version: PHP 7.4.16

The issue you are facing:
Every time I want to type any occ command in the cli, I get a message that the memory limit is exhausted.

root@30fa25654064:/var/www/html# sudo -u www-data php occ help

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

I’ve set the memory limit of php as a environment variable in the docker-compose file:

PHP_MEMORY_LIMIT=2048M
PHP_UPLOAD_LIMIT=20G

And this seems to work because in the Nextcloud system page the memory limit of php is set to that value.
However I cannot type any occ command, because of the error above.

Is this the first time you’ve seen this error? (Y/N): Y
Steps to replicate it:

  1. Set php memory limit as an environment variable in docker-compose.
  2. Verify that the limit is set successfully in the Nextcloud system page.
  3. See that one cannot enter any occ commands.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

root@30fa25654064:/var/www/html# cat config/config.php 
<?php
$CONFIG = array (
  'config_is_read_only' => false,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'nextcloud_redis',
    'port' => 6379,
  ),
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'trusted_proxies' => 
  array (
    0 => '172.18.0.5',
  ),
  'instanceid' => '',
  'passwordsalt' => '',
  'secret' => '',
  'trusted_domains' => 
  array (
    0 => '',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '21.0.0.18',
  'overwrite.cli.url' => '',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => 'db',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => '',
  'dbpassword' => '',
  'installed' => true,
  'maintenance' => false,
  'app_install_overwrite' => 
  array (
    0 => 'drawio',
    1 => 'weather',
  ),
  'loglevel' => 2,
  'encryption.legacy_format_support' => false,
  'encryption.key_storage_migrated' => false,
  'ldapIgnoreNamingRules' => false,
  'ldapProviderFactory' => 'OCA\\User_LDAP\\LDAPProviderFactory',
  'default_phone_region' => 'DE',
  'twofactor_enforced' => 'true',
  'twofactor_enforced_groups' => 
  array (
    0 => 'admin',
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
  ),
);

My docker-compose:

version: '3'

services:
  db:
    image: mariadb
    container_name: nextcloud_db
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: always
    volumes:
      - db:/var/lib/mysql
    env_file:
      - db.env
    networks:
      - proxy

  app:
    build: ./app
    container_name: nextcloud_app
    restart: always
    volumes:
      - nextcloud:/var/www/html
      - ./app/config:/var/www/html/config
      - ./app/www.conf:/usr/local/etc/php-fpm.d/www.conf
    environment:
      - MYSQL_HOST=db
    env_file:
      - db.env
    depends_on:
      - db
      - redis
    networks:
      - proxy

  web:
    build: ./web
    container_name: nextcloud_web
    restart: always
    volumes:
      - nextcloud:/var/www/html:ro
      - ./web/nginx.conf:/etc/nginx/nginx.conf
    labels:
        # ... unrelated ...
    depends_on:
      - app
    networks:
      - proxy
    
  redis:
    container_name: nextcloud_redis
    image: redis:alpine
    restart: always
    networks:
      - proxy

volumes:
  db:
  nextcloud:

networks:
  proxy:
    external: true

I’ve removed sensitive informations from the files.

Thank you for your help!

Hello Konqi,

Somehow I have the same problem when executing occ commands inside my container. Another to execute occ command outside the container is by defining docker execute. For example i want to execute the occ command files:scan --all. The command would look like this:

docker exec -t -u www-data CONATINER ID/NAME php /var/www/html/occ files:scan --all

where you replace CONATINER ID/NAME with your container id OR container name. The way you find this info is by executing:

docker ps

I hope this helps :slight_smile:

Thank you Cyrus, your suggestion works! :slight_smile:

Still, this is a strange problem, and in fact that it works when the command is executed outside of the container makes it even stranger.

Your suggestion is a good enough workaround for me I think - but the problem is still there and we both might not be the only ones affected of this. So I will leave this thread open for now, maybe someone else finds the root cause of this.