Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the password for using "sudo apt-get install" command? #949

Closed
blatoo opened this issue Oct 13, 2019 · 14 comments · Fixed by #961
Closed

What is the password for using "sudo apt-get install" command? #949

blatoo opened this issue Oct 13, 2019 · 14 comments · Fixed by #961
Labels
tag:Documentation Related to user, developer, and maintainer documentation type:Question A question about the use of the docker stack images

Comments

@blatoo
Copy link

blatoo commented Oct 13, 2019

Hi all,

I want to install some software on the docker container, but when I use apt-get install xxx, then I will get a "permission denied" problem. So I guess, I should use "sudo apt-get install xxx", my question is what is the password for the sudo command?

@Bidek56
Copy link
Contributor

Bidek56 commented Oct 17, 2019

There's no password as far as I know. Have you tried adding "-e GRANT_SUDO=yes" as illustrated below?

docker run -d -v $PWD:/home/jovyan/work -e GRANT_SUDO=yes --user root -p 8888:8888 jupyter/all-spark-notebook

@narquette
Copy link

Running into the same issue. Trying to install curl.

@DrPaulBrewer
Copy link

Reading the docker files, I see they point back to jupyter/base-image and from there, back to:
ubuntu:bionic-20190612@sha256:9b1702dcfe32c873a770a32cfd306dd7fc1c4fd134adfb783db68defc8894b3c.

So the ubuntu:bionic pinned image runs as root, and does not have sudo.

Trying sudo from docker run -it jupyter/base-image /bin/bash requests a password.

The Dockerfile creates the jupyter user here.

The man page for useradd discloses under -p that the default is not no password, but a disabled password. Between having a disabled password and not being in the sudoers file, using sudo against the base image without start.sh opening up sudo isn't going to work...

The start.sh script will open up password-less sudo if you pass an ENV with GRANT_SUDO=1 (or yes).

@DrPaulBrewer
Copy link

DrPaulBrewer commented Oct 27, 2019

I'm not an official project volunteer, so someone with more knowledge might want to chime in.

This worked for me.

To build your own custom jupyter docker image with curl

  1. Decide what base image you are going to use. Here I used jupyter/scipy-notebook
  2. Create a directory where the custom build will go. Here we will name it ./jupyter-scipy-curl
  3. Create ./jupyter-scipy-curl/Dockerfile with this content:
FROM jupyter/scipy-notebook
# must reset to user root to install more stuff
USER root
# apt-utils is missing and needed to avoid warning about skipping debconf
RUN apt-get update && apt-get --yes install apt-utils
# install whatever else you want on this line
RUN apt-get --yes install curl
# set the user back to original setting
USER $NB_UID
  1. docker build -t your-name-here/jupyter-scipy-curl ./jupyter-scipy-curl

To test:

docker run -it your-name-here/jupyter-scipy-curl /bin/bash
jovyan@053666d05bb0:~$ 
jovyan@053666d05bb0:~$ curl
curl: try 'curl --help' or 'curl --manual' for more information
jovyan@053666d05bb0:~$ exit
exit

@blatoo
Copy link
Author

blatoo commented Oct 27, 2019

There's no password as far as I know. Have you tried adding "-e GRANT_SUDO=yes" as illustrated below?

docker run -d -v $PWD:/home/jovyan/work -e GRANT_SUDO=yes --user root -p 8888:8888 jupyter/all-spark-notebook

I tried, but it doesn't work for me...

@Bidek56
Copy link
Contributor

Bidek56 commented Oct 28, 2019

I have just tried:
docker run -d -v $PWD:/home/jovyan/work -e GRANT_SUDO=yes --user root -p 8888:8888 jupyter/all-spark-notebook

then

sudo apt install wget
sudo apt update
sudo apt upgrade

It all works fine, what error messages do you see?

@Bugatti100Peagle
Copy link

I have just tried:
docker run -d -v $PWD:/home/jovyan/work -e GRANT_SUDO=yes --user root -p 8888:8888 jupyter/all-spark-notebook

then

sudo apt install wget
sudo apt update
sudo apt upgrade

It all works fine, what error messages do you see?

I try it OK,thanks

@parente parente mentioned this issue Nov 9, 2019
@parente
Copy link
Member

parente commented Nov 9, 2019

This question comes up from time to time. I've opened a PR adding more explicit section in the documentation about how to grant the NB_USER passwordless sudo and brief explanation about why password auth is disabled.

@parente parente added tag:Documentation Related to user, developer, and maintainer documentation type:Question A question about the use of the docker stack images labels Nov 9, 2019
@marscod
Copy link

marscod commented Sep 18, 2020

adding the following to the base model, works for me: -e GRANT_SUDO=yes --user root

@RichardBronosky
Copy link

RichardBronosky commented Jan 11, 2021

If you want to understand the docker run -it --rm -e GRANT_SUDO=yes thing, see https://github.com/jupyter/docker-stacks/blob/master/base-notebook/start.sh#L89-L93

I will add that if the way the maintainers have chosen to handle users and password, you can change it in a Dockerfile. I explain how to add/change user/password in https://askubuntu.com/a/1307156/146273

username=jovyan
password=jovyan

adduser --gecos "" --disabled-password $username
chpasswd <<<"$username:$password"

This would also work if username=root, but you will need to prevent pam from denying use of su (default behavior in base-notebook). I do this in my Dockerfile like so:

sed -Ei 's/(.*pam_deny.so)/# \1/' /etc/pam.d/su

@rjurney
Copy link

rjurney commented Oct 24, 2021

You need to do this in docker-compose:

version: "3.8"
services:

    agile:
        tty: true
        image: jupyter/pyspark-notebook:latest
        user: root
        environment:
            GRANT_SUDO: "yes"

@gerroon
Copy link

gerroon commented Feb 4, 2024

GRANT_SUDO in docker compose does not work. I have it enabled

      - JUPYTER_ENABLE_LAB=yes
      - GRANT_SUDO=yes
      - JUPYTER_TOKEN=''
      - JUPYTER_PASSWORD=''
      -
jovyan@bfbef172b26f:~$ sudo su
[sudo] password for jovyan:

@mathbunnyru
Copy link
Member

@gerroon you need to use user: root.

https://jupyter-docker-stacks.readthedocs.io/en/latest/using/recipes.html#using-sudo-within-a-container

@gerroon
Copy link

gerroon commented Feb 10, 2024

This is how one can login as su

docker exec -it -u root container bash

@mathbunnyru thanks, but that one does not give any docker-compose setting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tag:Documentation Related to user, developer, and maintainer documentation type:Question A question about the use of the docker stack images
Projects
None yet
Development

Successfully merging a pull request may close this issue.