How to run a command as www-data in Docker image

Hi;

It is more a curiosity than an issue but I was wondering how you and you and maybe you too run command as www-data inside the Docker image ?

Right now, when it require I install sudo than

such as an example :

sudo - www-data occ app:list

but I see the command su so I would like to know if I’m just doing something wrong because any variation such as

su - www-data occ app:list
su www-data occ app:list
su - www-data -c ‘occ app:list’
su www-data -c “occ app:list”

simply repeat over and over :
This account is currently not available.

So if someones want to enlighten me :wink:

su and sudo are difference commands, and so will behave differently. Try running man su and man sudo and comparing the difference.

Correct syntax is sudo -u www-data php occ command

There is also an app (non official) that is a web occ console.

Hope this help

The cause of the issue may be that the www-data user has no shell configured :
/bin/false (or some other variant) in /etc/passwd
The su command, called with the - opt, tries to open a shell, but it get denied by the system.
hence the error message.

solution, If you really have no choice :

  • Change temporarily the shell of the www-data user to be able to use it with su
    (Use chsh or edit/etc/passwd directly. )

As said before me, best use case for occ is to use it with sudo command

su - www-data -c ‘occ app:list’

This is the good one BTW

Regards

from the hosts cli.

docker exec --user www-data <nextcloud-container-name> php occ <your-command>

no need to login the container.

6 Likes

I agree with @Reiner_Nippes, no need to log into the container :slight_smile: