Will's avatar

⬅️ See more posts

Interacting with a Nextcloud instance deployed with Docker

28 January 2022 (2 minute read)

🔮 This post is also available via Gemini.

technology selfhost

If you’ve ever run your own Nextcloud before, you may have noticed screens like the following in your instance’s settings pages.

Nextcloud administration interface showing outstanding maintenance tasks

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.

Result of running occ via docker-compose exec

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.

✉️ You can reply to this post via email.

📲 Subscribe to updates

If you would like to read more posts like this, then you can subscribe via RSS.