diff --git a/base-notebook/Dockerfile b/base-notebook/Dockerfile index 40e3b221..b94cbef1 100644 --- a/base-notebook/Dockerfile +++ b/base-notebook/Dockerfile @@ -70,7 +70,7 @@ RUN sed -re "s/c.ServerApp/c.NotebookApp/g" \ # This healtcheck works well for `lab`, `notebook`, `nbclassic`, `server` and `retro` jupyter commands # https://github.com/jupyter/docker-stacks/issues/915#issuecomment-1068528799 HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 \ - CMD python /etc/jupyter/docker_healthcheck.py || exit 1 + CMD /etc/jupyter/docker_healthcheck.py || exit 1 # Switch back to jovyan to avoid accidental container runs as root USER ${NB_UID} diff --git a/base-notebook/docker_healthcheck.py b/base-notebook/docker_healthcheck.py old mode 100644 new mode 100755 index b187eabf..8b756c55 --- a/base-notebook/docker_healthcheck.py +++ b/base-notebook/docker_healthcheck.py @@ -1,16 +1,19 @@ +#!/usr/bin/env python3 +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. import json import os +from pathlib import Path import requests # A number of operations below delibrately don't check for possible errors # As this is a healthcheck, it should succeed or raise an exception on error -runtime_dir = "/home/" + os.environ["NB_USER"] + "/.local/share/jupyter/runtime/" -file_list = os.listdir(runtime_dir) -json_file = [s for s in file_list if s.endswith(".json")] +runtime_dir = Path("/home/") / os.environ["NB_USER"] / ".local/share/jupyter/runtime/" +json_file = next(runtime_dir.glob("*.json")) -url = json.load(open(runtime_dir + json_file[0]))["url"] +url = json.loads(json_file.read_bytes())["url"] url = url + "api" r = requests.get(url, verify=False) # request without SSL verification