Dockerfile services question?

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 USER instruction in your Dockerfile to specify the user inside the container that will start the process inside the container. By default, the USER instruction is set to root. Here is an example of how to use the USER instruction in a Dockerfile:

FROM debian:stretch
USER root
CMD ["echo", "hello"]

This Dockerfile will run the echo command as the root user inside the container. If you want to execute a command using the root user inside the Docker container, you can use the -u option with the docker exec command. For example, to execute a command using the root user inside the Docker container, you can use the following command:

$ docker exec -it -u 0 <container_name> bash

Here, the -u option is used to define the ID of the root user 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.