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

如何为GCP Vertex AI Workbench构建Python >=3.8兼容容器?

实现Vertex AI Workbench支持Python >=3.8的自定义镜像

核心结论

完全可以通过自定义构建Docker镜像的方式,打造支持Python 3.8及以上版本的Vertex AI Workbench基础容器。你可以通过ARG命令灵活指定Python版本,只要保证镜像包含Workbench运行必需的核心组件(Jupyter服务、身份验证工具、启动脚本等)即可。

示例Dockerfile

以下是适配Vertex AI Workbench的Python 3.9自定义镜像实现:

# 通过ARG指定Python版本,支持3.8/3.9/3.10等版本
ARG PYTHON_VERSION=3.9
FROM python:${PYTHON_VERSION}-slim-bullseye

# 环境配置,避免Python输出缓冲、自动处理Debian交互提示
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive

# 安装系统依赖(匹配官方镜像的核心工具集)
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    git \
    libssl-dev \
    openssh-client \
    wget \
    && rm -rf /var/lib/apt/lists/*

# 安装Workbench必需的Python包
RUN pip install --no-cache-dir \
    jupyterlab==3.6.3 \
    notebook==6.5.4 \
    google-cloud-aiplatform==1.35.0 \
    google-cloud-storage==2.10.0 \
    ipykernel==6.25.0

# 添加Workbench启动脚本,适配平台访问规则
RUN mkdir -p /usr/local/bin
COPY start.sh /usr/local/bin/start.sh
RUN chmod +x /usr/local/bin/start.sh

# 创建非root用户,符合Workbench安全规范
RUN useradd -m -s /bin/bash jupyter
USER jupyter
WORKDIR /home/jupyter

# 暴露Jupyter服务端口
EXPOSE 8080

# 设置容器启动命令
CMD ["start.sh"]

配套启动脚本start.sh内容

#!/bin/bash
set -e

# 启动Jupyter Lab,适配Vertex AI Workbench的访问参数
jupyter lab \
    --ip=0.0.0.0 \
    --port=8080 \
    --no-browser \
    --allow-root \
    --NotebookApp.token='' \
    --NotebookApp.password='' \
    --NotebookApp.allow_origin='*' \
    --NotebookApp.base_url="${NB_PREFIX:-/}"

构建与部署步骤

  1. 构建本地镜像:在包含Dockerfile和start.sh的目录下执行:
docker build --build-arg PYTHON_VERSION=3.9 -t vertex-workbench-python39 .
  1. 推送镜像到GCR:
# 标记镜像(替换[你的项目ID]为实际GCP项目ID)
docker tag vertex-workbench-python39 gcr.io/[你的项目ID]/vertex-workbench-python39
# 推送至容器仓库
docker push gcr.io/[你的项目ID]/vertex-workbench-python39
  1. 创建Workbench实例:在GCP控制台创建Vertex AI Workbench实例时,选择「自定义容器」选项,填入上述GCR镜像地址即可。

关键注意事项

  • Jupyter版本建议选择3.x系列,确保与Workbench的访问逻辑兼容
  • 启动脚本的核心参数不可随意修改,否则会导致Workbench无法正常连接Jupyter服务
  • 若需要额外依赖,可在Dockerfile的apt-get install或pip install环节添加对应命令

内容的提问来源于stack exchange,提问作者Brian Bien

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 14:46:01