I\'m using a Docker image which was built using the USER command to use a non-root user called dev
.
Inside a container, I\'m \"dev\", but I want to edit the
When you start the container, you will be root but you won't know what root's pw is. To set it to something you know simply use "passwd root". Snapshot/commit the container to save your actions.
You can log into the Docker container using the root user (ID = 0) instead of the provided default user when you use the -u
option. E.g.
docker exec -u 0 -it mycontainer bash
root (id = 0) is the default user within a container. The image developer can create additional users. Those users are accessible by name. When passing a numeric ID, the user does not have to exist in the container.
from Docker documentation
Update: Of course you can also use the Docker management command for containers to run this:
docker container exec -u 0 -it mycontainer bash
try the following command to get the root access
$ sudo -i
You can use the USER root command in your Dockerfile.