Change port from 8888 to say 7777 in JupyterLab Dockerfile?

I need to setup a Docker JupyterLab image to port 7777 instead of the default 8888. I tried to setup the Dockerfile with

ENV JUPYTER_PORT 7777

and also using “-e” parameter through “docker run” command line. This is how I tried to ran the image:

#!/bin/bash
docker run -p 7777:7777 -e JUPYTER_PORT=7777 -v "$PWD":/home/jovyan/work jupyter/mytest

None of them worked so far, with the following log:

Container must be run with group root to update passwd file
Executing the command: jupyter notebook
[I 07:15:53.098 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[W 07:15:53.457 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 07:15:53.519 NotebookApp] JupyterLab beta preview extension loaded from /opt/conda/lib/python3.6/site-packages/jupyterlab
[I 07:15:53.519 NotebookApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 07:15:53.538 NotebookApp] Serving notebooks from local directory: /home/jovyan
[I 07:15:53.538 NotebookApp] 0 active kernels
[I 07:15:53.538 NotebookApp] The Jupyter Notebook is running at:
[I 07:15:53.538 NotebookApp] http://[all ip addresses on your system]:8888/?token=9a9c4cde9e9b167a1d21ac494ec0377626045a7d5c7181eb
[I 07:15:53.538 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 07:15:53.539 NotebookApp] 
    
    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=9a9c4cde9e9b167a1d21ac494ec0377626045a7d5c7181eb

Is there any way to setup the file ~/.jupyter/jupyter_notebook_config.py as suggested here as this:

c.NotebookApp.port = 7777

in the Dockerfile?
My current Dockerfile is:

FROM jupyter/datascience-notebook:9f9e5ca8fe5a

# Install in the default python3 environment
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt && \
    fix-permissions $CONDA_DIR && \
    fix-permissions /home/$NB_USER
1 Like

Do you need Jupyter to run as port 7777 inside the Docker container, or is it sufficient to map port 7777 outside to 8888 inside:

docker run -it --rm -p 7777:8888 jupyter/base-notebook

The displayed connection URL will be incorrect, you’ll need to replace 8888 with 7777 but otherwise http://127.0.0.1:7777/?token=TOKEN should work.

Hi manics.

I tried but unfortunately it didn’t worked. I don’t know in which case I would need to change the internal container port, or if would it help. I need to access this notebook from external world, so that could be an issue?
Any other ideas are more than welcome

Hernán

This May '20 PR seems to add what you’re looking for: Add env variable support for port options (#5221) · jupyter/notebook@d2d50f1 · GitHub

docker run -it --rm -p 7777:7777 jupyter/base-notebook start.sh jupyter lab --port 7777