本頁說明如何根據其中一個標準的深度學習容器映像檔建立衍生容器。
如要完成本指南中的步驟,請使用 Cloud Shell 或任何已安裝 Google Cloud CLI 的環境。
事前準備
開始之前,請務必完成下列步驟。
完成「開始使用本機深度學習容器」一文「事前準備」一節中的設定步驟。
請確認您已為 Google Cloud 專案啟用計費功能。
啟用 Artifact Registry API。
流程
如要建立衍生容器,請使用類似下列的程序:
建立初始 Dockerfile 並執行修改指令。
首先,請使用可用的映像檔類型建立深度學習容器。然後使用 conda、pip 或 Jupyter 指令,視需要修改容器映像檔。
建構及推送容器映像檔。
建構容器映像檔,然後推送至 Compute Engine 服務帳戶可存取的位置。
建立初始 Dockerfile 並執行修改指令
請使用下列指令選取深度學習容器映像檔類型,並對容器映像檔進行小幅變更。這個範例說明如何從 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