That doesnt work as the www-data user doesnt own occ. Noone owns the file. This is a problem with docker that I couldnt manage to fix so far.
root@780ff3289924:/var/www/html# sudo -u www-data php occ db:add-missing-indices
Console has to be executed with the user that owns the file config/config.php
Current user: www-data
Owner of config.php:
Try adding 'sudo -u ' to the beginning of the command (without the single quotes)
If running with 'docker exec' try adding the option '-u ' to the docker command (without the single quotes)