Search code examples
docker-composejupyter-lab

setting JupyterLab password in DOcker Compose


I'm having a problem running JupyterLab locally, and setting the password via Docker Compose file. I can get it working via a docker run command, but not via Compose

This also works fine with the password set and stored within the container in ./jupyter/jupyter_server_config.json

But to maintain the password when I rebuild the container, I'd like to have the password set in the Compose file rather than saved into the JSON file.

I've found various answers around the web to include the argon hashed password into a docker run command, but can't find how to do this within a compose file.

services:
  jupyter:
    container_name: jup
    image: quay.io/jupyter/scipy-notebook:latest
    ports:
      - 8888:8888
    restart: unless-stopped
    environment:
      - TZ=Australia/Sydney
    command:
      - start-notebook.py
    volumes:
      - ./work:/home/joyvan/work
 

I've tried :-

command: - start-notebook.py --PasswordIdentityProvider.hashed_password='argon2:$argon2id$v=19$m=10240,t=10,p=8$dRrGNTESTDATAdKLm+YVjQ$FbTESTDATAG66kyt4vw3/+TjrT5jYtYXhy+v5QX0HY4' within the file. Also :-

command: - start-notebook.py - --PasswordIdentityProvider.hashed_password='argon2:$argon2id$v=19$m=10240,t=10,p=8$dRrGNTESTDATAdKLm+YVjQ$FbTESTDATAG66kyt4vw3/+TjrT5jYtYXhy+v5QX0HY4' I've also tried including the argon hash under environment variables PASSWORD and HASHED_PASSWORD, double quotes, single quotes, $$ rather than $ to escape the $ character - all with no success.


Solution

  • First check your docker compose version using docker compose version. Version 2.29.0 has a double dollar sign interpolation bug. This was fixed in version 2.29.1. You were on the right track though, you MUST replace $ signs in the hashed password with $$ signs. See Interpolation documentation.

    Next, edit your file to use one of two possible syntaxes. The first option passes the command directly in shell form. Type the command directly next to colon and NOT on a new line with a - sign like so:

    services:
      jupyter:
        container_name: jup
        image: quay.io/jupyter/scipy-notebook:latest
        ports:
          - 8888:8888
        restart: unless-stopped
        environment:
          - TZ=Australia/Sydney
        command: start-notebook.py --PasswordIdentityProvider.hashed_password='argon2:$$argon2id$$v=19$$m=10240,t=10,p=8$$dRrGNTESTDATAdKLm+YVjQ$$FbTESTDATAG66kyt4vw3/+TjrT5jYtYXhy+v5QX0HY4'
        volumes:
          - ./work:/home/joyvan/work
    

    Docker Compose treats new lines beginning with - as a list, even if it is only one line long. If you wish to enter command as a list, each parameter MUST be on a separate line. So the following would work:

    services:
      jupyter:
        container_name: jup
        image: quay.io/jupyter/scipy-notebook:latest
        ports:
          - 8888:8888
        restart: unless-stopped
        environment:
          - TZ=Australia/Sydney
        command:
          - start-notebook.py
          - --PasswordIdentityProvider.hashed_password='argon2:$$argon2id$$v=19$$m=10240,t=10,p=8$$dRrGNTESTDATAdKLm+YVjQ$$FbTESTDATAG66kyt4vw3/+TjrT5jYtYXhy+v5QX0HY4'
        volumes:
          - ./work:/home/joyvan/work
    

    However, this will NOT work:

        command:
          - start-notebook.py --PasswordIdentityProvider.hashed_password='argon2:$$argon2id$$v=19$$m=10240,t=10,p=8$$dRrGNTESTDATAdKLm+YVjQ$$FbTESTDATAG66kyt4vw3/+TjrT5jYtYXhy+v5QX0HY4'
    

    Refer to the 'command' section in docker compose documentation and 'cmd' section in docker file documentation. Also, you don't need to overthink / overuse quotes, but if you are ever in any doubt, refer to this YAML article.