创建派生容器

本页面介绍如何根据其中一个可用的标准 Deep Learning Containers 映像创建派生容器。

如需完成本指南中的步骤,您可以使用 Cloud Shell 或安装了 Google Cloud CLI 的任何环境。

准备工作

在开始之前,请确保您已完成以下步骤。

  1. 完成本地 Deep Learning Containers 容器使用入门的“准备工作”部分中的设置步骤。

  2. 确保您的 Google Cloud 项目已启用结算功能。

    了解如何启用结算功能

  3. 启用 Artifact Registry API。

    启用 API

流程

如需创建衍生容器,请使用与以下示例类似的流程:

  1. 创建初始 Dockerfile 并运行修改命令。

    首先,使用其中一种可用的映像类型来创建 Deep Learning Containers 容器。然后使用 conda、pip 或 Jupyter 命令来根据需要修改容器映像。

  2. 构建并推送容器映像。

    构建容器映像,然后将其推送到 Compute Engine 服务账号可访问的位置。

创建初始 Dockerfile 并运行修改命令

使用以下命令选择 Deep Learning Containers 映像类型 并对容器映像稍作更改此示例展示了如何 先从 TensorFlow 映像开始, 最新版本的 TensorFlow。 将以下命令写入 Dockerfile:

FROM us-docker.pkg.dev/deeplearning-platform-release/gcr.io/tf-gpu:latest
# Uninstall the container's TensorFlow version and install the latest version
RUN pip install --upgrade pip && \
    pip uninstall -y tensorflow && \
    pip install tensorflow

构建并推送容器映像

使用以下命令构建容器映像并将其推送到 你可以通过 Artifact Registry Google Compute Engine 服务账号。

创建代码库并进行身份验证:

export PROJECT=$(gcloud config list project --format "value(core.project)")
gcloud artifacts repositories create REPOSITORY_NAME \
    --repository-format=docker \
    --location=LOCATION
gcloud auth configure-docker LOCATION-docker.pkg.dev

替换以下内容:

  • LOCATION:区域级或多区域级 的位置 代码库,例如 us。要查看 受支持的位置列表,请运行以下命令: gcloud artifacts locations list.
  • REPOSITORY_NAME:代码库的名称 例如 my-tf-repo

然后,构建并推送映像:

export IMAGE_NAME="LOCATION-docker.pkg.dev/${PROJECT}/REPOSITORY_NAME/tf-custom:v1"
docker build . -t $IMAGE_NAME
docker push $IMAGE_NAME