Ubuntu – Don’t run this as Root! – Docker Image

docker

I'm running Ubuntu xenia in my docker container (this is a container running in my OS X VM Host). When you run the docker run command that created my container, it logs you in as root.

So when I try to install Linuxbrew after all this and after installing curl and ruby in my container via app-gret, I get the error don't run this as root! when I try to then install Linuxbrew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"

I want to be able to sill run this somehow. If docker run logs me in as root, what are my options here to get around this limitation on root so I can still run this command? If docker always logs me in as root to a container, what do people usually do in the situations where they want to install stuff like this as a non-root user on a container with Ubuntu?

Note: I'm new to both Ubuntu, Linux, and docker. So that implies I may not be aware of all basics and there is a lot to know.

Best Answer

You can use the USER command to change the user commands are run as. Of course you need to create the user first, so your Dockerfile would contain something like this:

RUN useradd --system -s /sbin/nologin someuser

USER someuser
Related Question