Docker: occ error Failed to set memory limit to 0 bytes

Hello,

I’m experimenting with Nextcloud and I’m fairly new :slight_smile:

I’m using the latest official Nextcloud docker image.

As I understand it, when I build the image and run the container, additional setup is required by going on the web interface and creating the admin account and enabling certain apps.

In my case, I would like to build the image non-interactively and I’ve learned that the php occ feature is how I can do this, except when I include these commands in my Dockerfile and build the image, I get the error Could not open input file: /var/www/html/occ.

When I build just the base image without the occ commands and docker exec into the container the command works just fine. I suppose there’s something conflicting in the backend which doesn’t allow me to run occ before the container is built.

I’d like to know if there’s a way around this where I can have the Nextcloud image with the admin and external storage already set up without intervention.

My Dockerfile looks like this:

FROM nextcloud:latest


RUN apt-get update && apt-get upgrade -y

RUN apt-get install -y libz-dev libpcre3-dev sudo

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"

RUN mv composer.phar /usr/local/bin/composer

RUN composer require aws/aws-sdk-php

RUN chmod 755 -R /var/www

# Testing the occ command
RUN sudo -u www-data php /var/www/html/occ list


CMD ["apache2-foreground"]

The result of docker build:

#17 [13/13] RUN sudo -u www-data php /var/www/html/occ list
#17 sha256:fa3ccf0b42bb63c1dacb6e476ccb30395de21fc84ccb23eaed8eb77e6dd3f2dc
#17 0.378 
#17 0.378 Warning: Failed to set memory limit to 0 bytes (Current memory usage is 2097152 bytes) in Unknown on line 0
#17 0.378 Could not open input file: /var/www/html/occ
#17 ERROR: executor failed running [/bin/sh -c sudo -u www-data php /var/www/html/occ list]: exit code: 1

Please let me know if I can provide more details, thanks!

hi @Rica_De_Vera welcome to the forum :handshake:

Please use the search - lot of issues have been discussed already

I didn’t try to run occ inside on the dockerfile… in fact I’m not sure it’s a good idea.
you can run occ commands inside the container from your Docker host e.g.

docker exec --user www-data <container name> php occ maintenance:mode --on
docker exec --user www-data <container name> php occ maintenance:mode --off

regarding memory issues you might want to add -d memory_limit=512M e.g.
sudo -u www-data php -d apc.enable_cli=1 -d memory_limit=512M occ maintenance:mode --off

Hey! Thanks for your reply.

Unfortunately I have not come across a discussion that answers my question hence I made my own.

I specifically want a Nextcloud image that has the complete set up without having to docker exec into the container as I plan on using it in AWS ECS with the Fargate launch type where I will not have access to the container.

If it is not possible or not recommended then I will just have to rethink my strategy :sweat_smile:

Thanks again!

give it a try and report back.

BTW: your Docker instructions are not optimal - you should try to avoid many different ‘RUN’ instructions and combine as many as possible into 1 instruction RUN command 1; command 2; command 3 it’s more effective (not 100% sure but I think each instruction creates an additional layer which makes the image more complex/bloated).

You can auto-configure all the basic parameters to have a running NC. See the docs on the Docker hub page or most up-to-date here. None of that requires touching the image/Dockerfile.

If you do wish to custom the image via the Dockerfile/etc, see here including examples.