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.


4 Answers 4


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

A Google search lead me to this. I personally don't think it's a nice and clean solution, but it should be able to do the job. What this solution does is the following:

Instead of directly starting the program in the container, there is a two-step launch going on: First, a small script is launched with docker, which basically creates a new user in the container, and then executes the main program as this new user. This is the script that is used there, /home/r/script.sh being the program that is to be started:

adduser --disabled-password --gecos '' r
adduser r sudo
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
su -m r -c /home/r/script.sh

If you want a shell as that user, you might be able to put bash there instead.

  • Christ, thanks did not see that link yet. This is painful. Commented Jan 3, 2016 at 0:16

You can use:

useradd -m linuxbrew
sudo -u linuxbrew -i /bin/bash
yes | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"

Here is link to original documentation from Linuxbrew

  • 1
    What is the default password after creating this linuxbrew user?
    – Alfran
    Commented Jan 11, 2018 at 9:25
  • This presumes sudo is available.
    – rainabba
    Commented May 8, 2020 at 21:40
  • @Alfran it's password - just tested this right now after running into the same question
    – Ronak Shah
    Commented Jul 20, 2020 at 23:37

Since you can "log out" of root from command line, run the first command that logged you in as root, type exit, (logs you out) and then run the command that tells you to "Don't run this as root!".

  • You should read the first sentence in the question.
    – rainabba
    Commented May 8, 2020 at 21:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .