Best practice is to not have root permissions inside a container. Many times, with Docker you do. I usually use Podman. It’s daemonless and non-root by default.
In your Dockerfile I think the default is to run as root unless you say otherwise, but I could be wrong. You can specifically run as root in the Dockerfile and then it should stay running as root unless you switch to another user.
The Bingbot says:
To run a Dockerfile as root, you can use the
USERinstruction in your Dockerfile to specify the user inside the container that will start the process inside the container. By default, theUSERinstruction is set toroot. Here is an example of how to use theUSERinstruction in a Dockerfile:FROM debian:stretch USER root CMD ["echo", "hello"]This Dockerfile will run the
echocommand as therootuser inside the container. If you want to execute a command using therootuser inside the Docker container, you can use the-uoption with thedocker execcommand. For example, to execute a command using therootuser inside the Docker container, you can use the following command:$ docker exec -it -u 0 <container_name> bashHere, the
-uoption is used to define the ID of therootuser inside the container ¹²³⁴.Source: Conversation with Bing, 1/9/2024
(1) dockerfile - Run docker as root verus non-root - Stack Overflow. dockerfile - Run docker as root verus non-root - Stack Overflow.
(2) Root User and Password Inside a Docker Container - Baeldung. https://www.baeldung.com/ops/root-user-password-docker-container.
(3) Docker Tip #91: Exec into a Container as Root without Sudo or a … Docker Tip #91: Exec into a Container as Root without Sudo or a Password — Nick Janetakis.
(4) Running Docker Containers as ROOT: | dockerlabs. Running Docker Containers as ROOT: | dockerlabs.
(5) Dockerfile reference | Docker Docs. Dockerfile reference | Docker Docs.