0

Currently, my workflow is to use an alias for the jupyter lab command via RUN echo 'alias...' at the end of my Dockerfile:

RUN echo 'alias jupyterlab="jupyter lab --ip=0.0.0.0 --port=8117 --no-browser --allow-root"' >> ~/.bashrc

which enables me to open up the JupyterLab container in my browser at port-number 8117, using just the command jupyterlab.

I would like to try to generalise this so that any valid port_number can be submitted as a build argument when building the Dockerfile, via e.g.,

docker build -t <image_name> . --build-arg PORTNUM=<port_number>

by changing the Dockerfile. Since Bash alias doesn't take arguments, I tried to adapt this solution:

RUN echo 'jupyterlab() { jupyter lab --ip=0.0.0.0 --port="$PORTNUM" --no-browser --allow-root ; }' >> ~/.bashrc

but now I get error

traitlets.traitlets.TraitError: The 'port' trait of a ServerApp instance must be an int, but a value of '' <class 'str'> was specified.

which suggests that no argument ended up being passed to the $PORTNUM. Anyone know how to fix this?

  • I think you may need to take the quotes out from around `"$PORTNUM"`. Maybe try referencing it like `--port=$PORTNUM` or `--port=${PORTNUM}` – Alex May 06 '22 at 15:03
  • Usually a container startup doesn't read shell dotfiles at all, so the `.bashrc` file has no effect; and it usually doesn't run a shell, so a bash-specific `alias` also has no effect. Is this in the context of a larger container setup? What's the main container `CMD`? – David Maze May 06 '22 at 17:42

0 Answers0