I'm new to docker. When I run a docker images like ubuntu image by using the command,
sudo docker run -i -t ubuntu:14.04
By default, it is entering into the container as root like this.
I searched regarding this, but I couldn't get any of how to start a docker image as a non root user as I'm completely a starter for this topic.
It would be great if someone explains with an example of how to run a docker image as a non root user.
This is admittedly hacky, but good for those quick little containers you start just to test something quickly:
Full version of the script I use here:
https://github.com/ericcurtin/staging/blob/master/d-run
It is not advisable to allow running docker without sudo as Docker has no auditing or logging built in, while sudo does. If you want to give docker access to non-root users Red Hat recommends setting up sudo. Add an entry like the following to /etc/sudoers.
Now, set up an alias in ~/.bashrc for running the docker command:
Now when the user executes the docker command as non-root it will be allowed and get proper logging.
Look at the journal or /var/log/messages.
the
docker run
command has the-u
parameter to allow you to specify a different user. In your case, and assuming you have a user namedfoo
in your docker image, you could run:NOTE: The
-u
parameter is the equivalent of theUSER
instruction for Dockerfile.