Docker-stacks: What is the password for using "sudo apt-get install" command?

Created on 13 Oct 2019  路  10Comments  路  Source: jupyter/docker-stacks

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?

Documentation Question

Most helpful comment

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.

All 10 comments

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

Running into the same issue. Trying to install curl.

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

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

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

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

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.

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

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
Was this page helpful?
0 / 5 - 0 ratings