使用 SageMaker Studio JupyterLab 環境的自訂映像時,如何疑難排解問題?
我想要疑難排解使用自訂映像來建置 Amazon SageMaker Studio JupyterLab 環境時發生的問題。
解決方法
**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
確認您的權限
SageMaker Studio 使用者的自訂 IAM 政策必須包含 sagemaker.ListImage 權限,才能建立空間,以及檢視並列出映像。
使用 WORKDIR Dockerfile 指示
與 SageMaker Studio 關聯的 Amazon Elastic Block Store (Amazon EBS) 磁碟區會掛載在 /home/sagemaker-user。您無法變更掛載路徑。若要確保自訂映像在 /home/sagemaker-user 內運作,請將 WORKDIR Dockerfile 指示新增至 /home/sagemaker-user 內的子資料夾,以設定映像的工作目錄。如需更多資訊,請參閱 Dockerdocs 網站上的 WORKDIR。
注意:請勿在自訂映像中使用 /opt/.sagemakerinternal、/opt/ml 或 /var/log/studio 保留目錄。SageMaker AI 使用這些目錄來存放其中繼資料和日誌。
檢查 Dockerfile 組態
下列 Docker 檔案範例會安裝 Python 套件,並將範圍設定為沒有權限的使用者:
FROM public.ecr.aws/amazonlinux/amazonlinux:2 ARG NB_USER="sagemaker-user" ARG NB_UID="1000" ARG NB_GID="100" RUN yum install —assumeyes python3 shadow-utils && \ useradd —create-home —shell /bin/bash —gid "${NB_GID}" —uid ${NB_UID} ${NB_USER} && \ yum clean all && \ python3 -m pip install jupyterlab RUN python3 -m pip install —upgrade pip RUN python3 -m pip install —upgrade urllib3==1.26.6 USER ${NB_UID} CMD jupyter lab —ip 0.0.0.0 —port 8888 \ --ServerApp.base_url="/jupyterlab/default" \ --ServerApp.token='' \ --ServerApp.allow_origin='*'
檢閱您的日誌
如果您建立或啟動自訂映像時仍遇到問題,請檢閱 Amazon CloudWatch Logs 中的 SageMaker AI Studio 日誌。在 /aws/sagemaker/studio 日誌群組和 domain-id/app-name/JupyterLab/default 日誌串流中找出錯誤訊息。
根據您在日誌中找到的錯誤訊息來疑難排解問題。
解決「NotFoundError」錯誤訊息
當使用者 ID (UID) 和群組 ID (GID) 的 Docker 規格與自訂映像定義不相符時,您會收到以下錯誤訊息:
「NotFoundError: SageMaker is unable to launch the app using the image [Image ARN].Ensure that the UID/GID provided in the AppImageConfig matches the default UID/GID defined in the image.」
檔案系統支援 sagemaker-user 使用者名稱。SageMaker 支援 UID 1000 和 GID 100。建置 Dockerfile 時,請將 UID 設定為 1000,並將 GID 設定為 100。如有需要,請授予使用者 sudo 權限。
若要解決此問題,請完成下列步驟:
-
建置映像後,請執行以下命令來驗證使用者組態:
docker run -it $IMAGE_URI預期輸出:
UID=1000(sagemaker-user) GID=100(sagemaker-user) groups=100(sagemaker-user) -
請確認 Dockerfile 包含啟動 JupyterLab 伺服器所需的組態。將以下 CMD Dockerfile 指示新增至檔案:
CMD jupyter lab —ip 0.0.0.0 —port 8888 \ —ServerApp.base_url="/jupyterlab/default" \ —ServerApp.token='' \ —ServerApp.allow_origin='*'```**注意:**如需 CMD 指示的詳細資訊,請參閱 Dockerdocs 網站上的 CMD。
-
執行 describe-app-image-config AWS CLI 命令,確認自訂映像的 AppImageConfig 具有正確的 UID 和 GID:
aws sagemaker describe-app-image-config —app-image-config-name APP-CONFIG-NAME**注意:**將 APP-CONFIG-NAME 替換為您的應用程式映像組態名稱。您也可以使用 SageMaker AI 主控台檢視應用程式映像組態。
解決「ContainerExecutionFailedError」錯誤訊息
如果您搭配 SageMaker Studio 使用 JupyterLab 時,Dockerfile 沒有必要的組態,則可能會收到以下錯誤訊息:
「Creating JupyterLab application for space: hc-test-new ContainerExecutionFailedError: SageMaker is unable to launch the app because the container entrypoint for image [43xxxxx0.dkr.ecr.eu-central-1.amazonaws.com/jupyterlab-custom-hc@sha256:bae93f0342ba56624b132159354a22d540d65d200a0624dae637a4c005b66789] is not configured correctly.Please change the entrypoint for the image or use a different image to launch the app.Output: [App container prematurely exited with status [exited], exit code [1], and error [].」
若要解決此問題,請將以下必要組態新增至 Dockerfile:
-
使用包含 Python 3.x 的基礎映像。
-
執行以下命令來安裝 JupyterLab:
pip install jupyterlab -
設定以下必要的環境變數:
ENV SHELL=/bin/bash ENV NB_USER=sagemaker-user ENV NB_UID=1000 ENV NB_GID=100 -
如果還沒有 SageMaker 使用者,請執行以下命令來建立使用者:
useradd -m -s /bin/bash -N -u ${NB_UID} ${NB_USER} -
執行以下命令來設定工作目錄:
WORKDIR ${HOME} -
執行以下命令來設定使用者:
USER ${NB_USER} -
執行以下命令來設定進入點,以執行 JupyterLab:
ENTRYPOINT ["jupyter-lab"]CMD ["—ServerApp.ip=0.0.0.0", "—ServerApp.port=8888", "—ServerApp.allow_origin=*", "—ServerApp.token=''", "—ServerApp.base_url=/jupyterlab/default"]
解決「400 ResourceNotFound」錯誤訊息
如果 SageMaker Studio 中發生映像不相符,則您可能會收到以下錯誤訊息:
「[400] ResourceNotFound: Image with ARN arn:aws:sagemaker:us-east-1:123456789:image/codeeditor-image」
可能發生上述錯誤的原因如下:
- 您刪除了先前的映像版本,但未先將該版本與 SageMaker Studio 分離。
- 網域設定中的映像 Amazon Resource Name (ARN) 與可用的映像版本不相符。
- 參考的映像版本已不存在於您的 AWS 帳戶中。
若要解決此問題,請採取以下動作:
- 確認映像版本存在於您的帳戶中。
- 請確認您已將映像正確連接至 SageMaker Studio。
- 執行以下 update-domain 命令,更新至最新的 SageMaker Studio 映像:
**注意:**將 example-domain-name、example-image-name、example-image-version-number 和 example-domain-app-config-name 替換為您組態中的值。aws sagemaker update-domain \ --domain-id example-domain-name \ --default-user-settings '{ "JupyterLabAppSettings": { "CustomImages": [ { "ImageName": "example-image-name", "ImageVersionNumber": example-image-version-number, "AppImageConfigName": "example-domain-app-image-config-name" } ] }, "CodeEditorAppSettings": { "CustomImages": [ { "ImageName": "cbi-ds-sagemaker-base-code-editor-v1-image", "AppImageConfigName": "example-domain-app-image-config-name" } ] } }'
相關資訊
- 語言
- 中文 (繁體)

相關內容
已提問 2 年前
已提問 2 年前