You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Docker启动带自定义扩展的JupyterLab?问题求助

问题:Docker部署带自定义扩展的JupyterLab失败,求解决方案与示例

我尝试通过Docker启动带有自定义扩展(extensionTest)的JupyterLab,但未成功。想请教:

  • 该如何实现?能否提供操作示例?
  • 适合的最佳基础Docker镜像是什么?

现有Dockerfile

FROM jupyter/minimal-notebook:lab-3.2.3

RUN pip install --no-cache-dir \
        astropy \
        ipytree \
        ipywidgets \
        jupyter \
        numpy \
        poliastro


RUN jupyter labextension install \
        jupyterlab-plotly@4.14.2 \
        plotlywidget@4.14.2

RUN pip install jupyterlab_widgets

COPY ./extensions/ ./extensions/

WORKDIR ./extensions/

RUN python -m pip install ./extensionTest

RUN jupyter labextension extensionTest

ENTRYPOINT start.sh jupyter lab

报错信息

ERROR: Command errored out with exit status 1:

   command: /opt/conda/bin/python /opt/conda/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmp2m0biqur

       cwd: /home/jovyan/extensions/extensionTest

  Complete output (44 lines):

  INFO:hatch_jupyter_builder.utils:Running jupyter-builder

  INFO:hatch_jupyter_builder.utils:Building with hatch_jupyter_builder.npm_builder

  INFO:hatch_jupyter_builder.utils:With kwargs: {'build_cmd': 'build:prod', 'npm': ['jlpm']}

  INFO:hatch_jupyter_builder.utils:Installing build dependencies with npm.  This may take a while...

  INFO:hatch_jupyter_builder.utils:> /tmp/pip-build-env-gj35ixm0/overlay/bin/jlpm install

  yarn install v1.21.1

  info No lockfile found.

  [1/4] Resolving packages...

  warning @jupyterlab/application > @jupyterlab/apputils > url > querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.

  warning @jupyterlab/application > @jupyterlab/ui-components > @blueprintjs/core > popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1

  warning @jupyterlab/application > @jupyterlab/ui-components > @blueprintjs/core > react-popper > popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1

  warning @jupyterlab/builder > terser-webpack-plugin > cacache > @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs

  warning @jupyterlab/builder > @jupyterlab/buildutils > crypto@1.0.1: This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in.

  warning @jupyterlab/builder > @jupyterlab/buildutils > verdaccio > request@2.88.0: request has been deprecated, see https://github.com/request/request/issues/3142

  warning @jupyterlab/builder > @jupyterlab/buildutils > verdaccio > request > har-validator@5.1.5: this library is no longer supported

  warning @jupyterlab/builder > @jupyterlab/buildutils > verdaccio > request > uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

  [2/4] Fetching packages...

  warning @blueprintjs/core@3.54.0: Invalid bin entry for "upgrade-blueprint-2.0.0-rename" (in "@blueprintjs/core").

  warning @blueprintjs/core@3.54.0: Invalid bin entry for "upgrade-blueprint-3.0.0-rename" (in "@blueprintjs/core").

  error lib0@0.2.58: The engine "node" is incompatible with this module. Expected version ">=14". Got "12.4.0"

  error Found incompatible module.

  info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

  Traceback (most recent call last):

    File "/opt/conda/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>

      main()

    File "/opt/conda/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main

      json_out['return_val'] = hook(**hook_input['kwargs'])

    File "/opt/conda/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 261, in build_wheel

      return _build_backend().build_wheel(wheel_directory, config_settings,

    File "/tmp/pip-build-env-gj35ixm0/overlay/lib/python3.9/site-packages/hatchling/build.py", line 41, in build_wheel

      return os.path.basename(next(builder.build(wheel_directory, ['standard'])))

    File "/tmp/pip-build-env-gj35ixm0/overlay/lib/python3.9/site-packages/hatchling/builders/plugin/interface.py", line 136, in build

      build_hook.initialize(version, build_data)

    File "/tmp/pip-build-env-gj35ixm0/normal/lib/python3.9/site-packages/hatch_jupyter_builder/plugin.py", line 83, in initialize

      raise e

    File "/tmp/pip-build-env-gj35ixm0/normal/lib/python3.9/site-packages/hatch_jupyter_builder/plugin.py", line 78, in initialize

      build_func(self.target_name, version, **build_kwargs)

    File "/tmp/pip-build-env-gj35ixm0/normal/lib/python3.9/site-packages/hatch_jupyter_builder/utils.py", line 114, in npm_builder

      run(npm_cmd + ["install"], cwd=str(abs_path))

    File "/tmp/pip-build-env-gj35ixm0/normal/lib/python3.9/site-packages/hatch_jupyter_builder/utils.py", line 227, in run

      return subprocess.check_call(cmd, **kwargs)

    File "/opt/conda/lib/python3.9/subprocess.py", line 373, in check_call

      raise CalledProcessError(retcode, cmd)

  subprocess.CalledProcessError: Command '['/tmp/pip-build-env-gj35ixm0/overlay/bin/jlpm', 'install']' returned non-zero exit status 1.

问题分析与解决方案

核心问题

报错明确指出:error lib0@0.2.58: The engine "node" is incompatible with this module. Expected version ">=14". Got "12.4.0",即基础镜像自带的Node.js版本过低,不满足自定义扩展依赖的lib0包要求。

最佳基础镜像选择

推荐以下两类镜像:

  • jupyter/scipy-notebook:预装了科学计算常用库,适合数据分析场景,自带的Node.js版本通常>=14;
  • jupyter/minimal-notebook:lab-3.6.0+:轻量基础镜像,更新版本的tag自带Node.js 16.x及以上,能规避版本兼容问题。

修正后的Dockerfile示例

# 使用满足Node.js版本要求的基础镜像
FROM jupyter/minimal-notebook:lab-3.6.1

# 安装Python依赖,移除基础镜像已预装的jupyter包
RUN pip install --no-cache-dir \
        astropy \
        ipytree \
        ipywidgets \
        numpy \
        poliastro \
        jupyterlab_widgets

# JupyterLab 3.x推荐用pip安装扩展,替代labextension命令
RUN pip install --no-cache-dir \
        jupyterlab-plotly==5.15.0 \
        plotly==5.15.0

# 复制自定义扩展到容器标准用户目录
COPY ./extensions/ /home/jovyan/extensions/

# 安装自定义扩展
WORKDIR /home/jovyan/extensions/extensionTest
RUN python -m pip install .

# 验证扩展安装状态(可选)
RUN jupyter labextension list

# 规范启动命令格式
ENTRYPOINT ["start.sh", "jupyter", "lab"]

关键修改说明

  1. 升级基础镜像:选择lab-3.6.1版本,自带Node.js 16.x,满足依赖要求;
  2. 更换扩展安装方式:JupyterLab 3.x开始,官方推荐通过pip安装扩展,无需手动处理前端依赖;
  3. 移除冗余依赖:基础镜像已预装jupyter,无需重复安装;
  4. 规范路径:使用容器内标准用户目录/home/jovyan,避免权限问题;
  5. 修正启动命令:采用数组格式的ENTRYPOINT,避免shell解析异常。

构建与运行命令

# 构建自定义镜像
docker build -t jupyterlab-custom .

# 启动容器,映射端口和本地工作目录
docker run -p 8888:8888 -v ./notebooks:/home/jovyan/work jupyterlab-custom

内容的提问来源于stack exchange,提问作者José Mota

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 21:55:13