Don't run this as Root! - Docker Image

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 )"

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.

0

4 Answers

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:

#!/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.

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 )"

Here is link to original documentation from Linuxbrew

3

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

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like