Jupyter Docker Stack Advice for Mac

I want to run one of the Jupyter Docker Stack containers on a Mac and mount $HOME/projects for access while running the container. The UID and GID for the relevant user on the Mac are 501 and 20 respectively.

I do not care if inside the notebook I work from jovyan or if a new user is created.

I realize that jovyan normally runs with UID:GID at 1000:100.

What is the cleanest way to achieve what I want?

Attempting to align user and group numbers on the Mac is a recipe for disaster. Creating a new docker image just to change the values for jovyan to align to the Mac seems like overkill. Running inside the container as root and then patching file permissions on the Mac when I finish my work each session doesn’t seem right either.

I prefer to fire up containers with docker compose but here, a simple docker run command may suffice.

I am confused by the documentation and various internet examples, and to date, all I have managed to do is spin my wheels and trash the permissions for my account on the Mac.

You can just set the uid/gid used to run the container, e.g.
docker run -it -u 1234:1234 -v ~/jupyter:/home/jovyan -p 8888:8888 quay.io/jupyter/base-notebook
A corresponding username won’t exist but that often doesn’t matter.

Alternatively you can start the container as root (-u 0) and switch to a different UID/GID/username by setting some environment variables:

Thank you @manics, but when I executed a simplified version of what you suggested, things did not go well.

rerobbins@santana-wired devtools % docker run -it -u 512:20 -p 8888:8888 quay.io/jupyter/pytorch-notebook:2024-01-06 
Entered start.sh with args: jupyter lab
Running hooks in: /usr/local/bin/start-notebook.d as uid: 512 gid: 20
Done running hooks in: /usr/local/bin/start-notebook.d
There is no entry in /etc/passwd for our UID=512. Attempting to fix...
WARNING: unable to fix missing /etc/passwd entry because we don't have write permission. Try setting gid=0 with "--user=512:0".
WARNING: no write access to /home/jovyan. Try starting the container with group 'users' (100), e.g. using "--group-add=users".
Running hooks in: /usr/local/bin/before-notebook.d as uid: 512 gid: 20
Sourcing shell script: /usr/local/bin/before-notebook.d/10activate-conda-env.sh
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/conda/lib/python3.11/multiprocessing/spawn.py", line 122, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "/opt/conda/lib/python3.11/multiprocessing/spawn.py", line 131, in _main
  File "/opt/conda/lib/python3.11/multiprocessing/spawn.py", line 235, in prepare
PermissionError: [Errno 13] Permission denied: '/home/jovyan'

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.11/site-packages/conda/exception_handler.py", line 17, in __call__
        return func(*args, **kwargs)
      File "/opt/conda/lib/python3.11/site-packages/conda/cli/main.py", line 97, in main_sourced
      File "/opt/conda/lib/python3.11/site-packages/conda/base/context.py", line 464, in __init__
      File "/opt/conda/lib/python3.11/site-packages/conda/common/configuration.py", line 1418, in _set_search_path
        self._search_path = IndexedSet(self._expand_search_path(search_path, **kwargs))
      File "/opt/conda/lib/python3.11/site-packages/boltons/setutils.py", line 125, in __init__
      File "/opt/conda/lib/python3.11/site-packages/boltons/setutils.py", line 355, in update
        for o in other:
      File "/opt/conda/lib/python3.11/site-packages/conda/common/configuration.py", line 1391, in _expand_search_path
        if path.is_file() and (
      File "/opt/conda/lib/python3.11/pathlib.py", line 1267, in is_file
        return S_ISREG(self.stat().st_mode)
      File "/opt/conda/lib/python3.11/pathlib.py", line 1013, in stat
        return os.stat(self, follow_symlinks=follow_symlinks)
    PermissionError: [Errno 13] Permission denied: '$XDG_CONFIG_HOME/conda/.condarc'

`$ /opt/conda/bin/conda shell.bash hook`

  environment variables:
                 CIO_TEST=<not set>
           CURL_CA_BUNDLE=<not set>
               LD_PRELOAD=<not set>
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>

     active environment : None
       user config file : /home/jovyan/.condarc
 populated config files : 
          conda version : 23.11.0
    conda-build version : not installed
         python version : 3.11.7.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=m1
       base environment : /opt/conda  (read only)
      conda av data dir : /opt/conda/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-aarch64
          package cache : /opt/conda/pkgs
       envs directories : /home/jovyan/.conda/envs
               platform : linux-aarch64
             user-agent : conda/23.11.0 requests/2.31.0 CPython/3.11.7 Linux/6.5.11-linuxkit ubuntu/22.04.3 glibc/2.35 solver/libmamba conda-libmamba-solver/23.12.0 libmambapy/1.5.6
                UID:GID : 512:20
             netrc file : None
           offline mode : False

I followed your other comments and things seem to work.

docker run -it --user root -e NB_UID=512 -e NB_GID=20 -v ~/projects:/home/jovyan/projects -p 8888:8888 quay.io/jupyter/pytorch-notebook:2024-01-06
1 Like