docker icon indicating copy to clipboard operation
docker copied to clipboard

Sudo not installed in docker container

Open dejj opened this issue 5 years ago • 4 comments

In order to run occ one needs sudo -u www-data occ, as recommended by the script itself. However, sudo is not installed in the docker container. To install sudo, one first must apt update && apt install sudo.

Are there any considerations to having sudo pre-installed, or not pre-installed in the container?

dejj avatar Mar 18 '20 23:03 dejj

as workaround, you don't need sudo, You can run on host this command:

docker exec -u <user> -it <container> bash

then you will be in shell with selected user

rchovan avatar Mar 19 '20 19:03 rchovan

That does indeed work, even with the user's shell being disabled! Thank you for that pointer :)

dejj avatar Mar 19 '20 19:03 dejj

in the case of mine, the user did not exist outside the docker container but you could get the userid (for www-data) from inside the docker and use it to connect as such: docker exec -u 33 -it nextcloud bash

petrosmm avatar Jun 10 '22 13:06 petrosmm

Sudo should not be installed in containers (it would be an extreme edge case for it to be needed). Any extra software is a potential maintenance/security issue. Running docker exec with the www-data user (or userid) is the correct solution.

Ideally the container wouldn't be running as the root user, but that is a different issue.

especially-relative avatar Jun 21 '22 18:06 especially-relative