2

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.

3

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:

#!/bin/bash
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. – PositiveGuy Jan 3 '16 at 0:16
6

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
1

You can use:

useradd -m linuxbrew
sudo -u linuxbrew -i /bin/bash
PATH=~/.linuxbrew/bin:/usr/sbin:/usr/bin:/sbin:/bin  
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 Jan 11 '18 at 9:25
0

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!".

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.