jupyterhub / repo2docker

Turn repositories into Jupyter-enabled Docker images
https://repo2docker.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.63k stars 362 forks source link

adduser: The user `root' already exists. #267

Closed spMohanty closed 5 years ago

spMohanty commented 6 years ago

In a fresh installation of docker-ce on Ubuntu-16.04, if I try to locally build a binder repository, then I get the following logs (and finally the error):

root@myserver:/mount/SDE/crowdAI/conda# repo2docker . --no-run
Using CondaBuildPack builder
Step 1/28 : FROM buildpack-deps:artful
 ---> 766d0aa6a29e
Step 2/28 : RUN apt-get update &&     apt-get install --yes --no-install-recommends locales &&     apt-get purge &&     apt-get clean &&     rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> b173f69c6e6a
Step 3/28 : RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen &&     locale-gen
 ---> Using cache
 ---> 3a5031e18af9
Step 4/28 : ENV LC_ALL en_US.UTF-8
 ---> Using cache
 ---> a221ace95304
Step 5/28 : ENV LANG en_US.UTF-8
 ---> Using cache
 ---> e0315886a2f4
Step 6/28 : ENV LANGUAGE en_US.UTF-8
 ---> Using cache
 ---> 0fc8bee8cc99
Step 7/28 : ENV SHELL /bin/bash
 ---> Using cache
 ---> 5fd1340b2573
Step 8/28 : ARG NB_USER
 ---> Using cache
 ---> 2b0535a59b11
Step 9/28 : ARG NB_UID
 ---> Using cache
 ---> 655d60cd28de
Step 10/28 : ENV USER ${NB_USER}
 ---> Using cache
 ---> 1bc2aa837513
Step 11/28 : ENV HOME /home/${NB_USER}
 ---> Using cache
 ---> ab2784542f9e
Step 12/28 : RUN adduser --disabled-password     --gecos "Default user"     --uid ${NB_UID}     ${NB_USER}
 ---> Running in bc1f2314bb1d
adduser: The user `root' already exists.
Removing intermediate container bc1f2314bb1d
The command '/bin/sh -c adduser --disabled-password     --gecos "Default user"     --uid ${NB_UID}     ${NB_USER}' returned a non-zero code: 1

This can be deterministically replicated by :

pip install jupyter-repo2docker
git clone https://github.com/binder-examples/conda
cd conda
repo2docker . --no-run
spMohanty commented 6 years ago

I do manage to get it to run by instead passing a custom user-name and user-id, but ideally I believe it should work with the default options.

repo2docker --no-run --user-id 1001 --user-name crowdai --debug . 
betatim commented 6 years ago

Thanks for this. I think we never considered anyone running repo2docker as root before.

The relevant bit of config is this bit here. It does the right thing most of the time (use the username of the user running repo2docker) except when you are root (or any other system account that already exists in the image). What do people think of special casing being executed as root and using jovyan as the user in the image in that case? An alternative would be to make the adduser command conditional inside the image.

minrk commented 6 years ago

user-id can be set with repo2docker --user-id=1000 --user-name=12345. I don't think we should special-case anything based on what the calling user is. Requiring users running as root to specify these arguments, since the image itself shouldn't build as root seems like the right thing to do.

choldgraf commented 6 years ago

@minrk could we just check for root with os.geteuid and then raise an informative error if user-id isn't explicitly set?

minrk commented 6 years ago

@choldgraf good idea. I imagine we can.

arnavs commented 5 years ago

If it still matters, just hit this issue in the master build of repo2docker on Ubuntu 18. Was running jupyter-repo2docker as sudo to avoid some permissions hassle with Docker.

betatim commented 5 years ago

Maybe the first thing to do here is to make repo2docker recognise it is being executed as root and stop with an error message pointing people to the --user-name and --user-id options.

I think trying to guess as what users we should be running is pretty hard, better to let the user decide for themselves. For the novice user the advice should probably be "you shouldn't be doing this, do X instead" and for the advanced user pointing them to the CLI options will let them figure out how to get unstuck.