Skip to content

Move environment setup from start.sh to ENTRYPOINT instead of CMD #1528

Closed
@manics

Description

@manics

What docker images this feature is applicable to?

  • jupyter/base-notebook
  • Notebooks that use startup hooks to configure the environment

What changes do you propose?

Split start-notebook.sh or start.sh into a script that does the environment setup in an ENTRYPOINT, and a script that does the actual notebook startup in CMD.

Originally suggested in jupyterhub/zero-to-jupyterhub-k8s#2138 (comment)

How does this change will affect users?

start-notebook.sh calls start.sh which handles a lot of setup in the Jupyter environment, including:

  • Running setup hooks such as for setting environment variables
    run-hooks /usr/local/bin/start-notebook.d
  • Customising user names and IDs when started as root
    # If the container started as the root user, then we have permission to refit
    # the jovyan user, and ensure file permissions, grant sudo rights, and such
    # things before we run the command passed to start.sh as the desired user
    # (NB_USER).
    #
    if [ "$(id -u)" == 0 ] ; then

Since start-notebook.sh is set as the CMD if someone passes any arguments when running the Docker container all this setup is ignored. For example
docker run -e NB_UID=12345 -u 0 jupyter/base-notebook jupyter-lab --debug
should change the UID from the default 1000 to 12345, but since the startup scripts aren't run this leads to an error (can't be run as root). Instead you must run
docker run -e NB_UID=12345 -u 0 jupyter/base-notebook start.sh jupyter-lab --debug

A concrete example of where this is a problem for users is in the pyspark notebook- it isn't obvious to a user that the pyspark environment is setup by a startup script rather than being baked into the Dockerfile.

Note we're working around this in JupyterHub 2.0 and Z2JH 2.0 with a breaking change: jupyterhub/zero-to-jupyterhub-k8s#2449
Instead of specifying jupyterhub-singleuser as the CMD when running the image we'll use the image's default CMD, but I think this change is still generally helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:EnhancementA proposed enhancement to the docker images

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions