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 /etc/hosts
file.
So I need to be root. I'm trying the su command, but I'm asked to enter the root password.
What's the default root user's password inside a Docker container?
I'd suggest a better solution is to give the
--add-host NAME:IP
argument to docker run when starting the container. That will update the/etc/hosts/
file without any need to become root.Otherwise, you can override the the
USER
setting by giving the-u USER
flag todocker run
. I would advise against this however, as you shouldn't really be changing things in a running container. Instead, make your changes in a Dockerfile and build a new image.try the following command to get the root access
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.
Get a shell of your running container and change the root password:
You can use the USER root command in your Dockerfile.