If you’ve ever run your own Nextcloud before, you may have noticed screens like the following in your instance’s settings pages.
The messages advise a number of maintenance procedures to help ensure the smooth running of your instance. These could be to run database migrations or to update schemas in response to installing new apps.
Often these steps might involve running occ
commands. occ
is Nextcloud’s command-line interface, and is so-called because of its origins in ownCloud.
If you deploy your Nextcloud using Docker, then it isn’t immediately obvious how to begin invoking the occ
command.
Invoking occ
on a running Nextcloud Docker container
Luckily, Docker makes this straight forward if you run Nextcloud in a container.
Assuming you manage your Docker orchestration using Docker Compose, if you wanted to run the occ db:add-missing-indices
command from the screenshot above on a Nextcloud Docker container, you could run the following from your project’s directory:
$ docker-compose exec --user www-data nextcloud php occ db:add-missing-indices
Where nextcloud
is the service’s name in your docker-compose.yml
file
If you don’t use Docker Compose, the same can be achieved using docker exec
directly:
$ docker exec --user www-data 0e4c3hd9s049 php occ db:add-missing-indices
Where 0e4c3hd9s049
is the ID for your Nextcloud container, which you can find by running docker ps
first.
In both cases, the command is structured the same. You may wish to note the --user
flag. In my case, I tell Docker to run the command as www-data
as that is the user that owns the Nextcloud config/config.php
file in my setup. If you use a different user, then update this value in your command.
You may also need to run the docker-compose
and docker
commands as a superuser, depending on whether your normal user is in the appropriate group.