Updated on 2024-06-21 GMT+08:00

Step 1 Creating a Custom Image

This section shows you how to create an image by loading an image creation template and writing a Dockerfile. Ensure that you have created the development environment and opened a terminal on the Notebook page. For details about Dockerfiles, see Dockerfile reference.

  1. Configure authentication information, specify a profile, and enter the account information as prompted. For more information about authentication, see ma-cli Authentication.

    ma-cli configure --auth PWD -P xxx

  2. Run env|grep -i CURRENT_IMAGE_NAME to query the image used by the current instance.

  1. Create an image.

    1. Obtain the SWR address of the base image.

      CURRENT_IMAGE_NAME=swr.ap-southeast-1.myhuaweicloud.com/atelier/pytorch_1_8:pytorch_1.8.0-cuda_10.2-py_3.7-ubuntu_18.04-x86_64-20220926104358-041ba2e

    1. Load an image creation template.

      Run the ma-cli image get-template command to query the image template.

      Run the ma-cli image add-template command to load the image template to the specified folder. The default path is where the current command is located. For example, load the upgrade_current_notebook_apt_packages image creation template.

      ma-cli image add-template upgrade_current_notebook_apt_packages

    2. Modify a Dockerfile.

      The Dockerfile in this example is modified based on the base PyTorch image pytorch1.8-cuda10.2-cudnn7-ubuntu18.04, the image template upgrade_current_notebook_apt_packages is loaded, and GCC and G++ are upgraded.

      After the image template is loaded, the Dockerfile will be automatically loaded in .ma/upgrade_current_notebook_apt_packages. The content is as follows and you can modify it based on your needs.

      FROM swr.ap-southeast-1.myhuaweicloud.com/atelier/pytorch_1_8:pytorch_1.8.0-cuda_10.2-py_3.7-ubuntu_18.04-x86_64-20220926104358-041ba2e
      
      # Set proxy to download internet resources
      ENV HTTP_PROXY=http://proxy.modelarts.com:80 \
          http_proxy=http://proxy.modelarts.com:80 \
          HTTPS_PROXY=http://proxy.modelarts.com:80 \
          https_proxy=http://proxy.modelarts.com:80
      
      USER root
      
      # Config apt source which can accelerate the apt package download speed. Also install ffmpeg and gcc-8 in root mode
      RUN cp -f /etc/apt/sources.list /etc/apt/sources.list.bak && \
          sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list && \
          sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list && \
          apt update && \
          apt -y install ffmpeg && \
          apt install -y --no-install-recommends gcc-8 g++-8 && apt-get autoremove -y && \
          update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8
      
      # ModelArts requires ma-user as the default user to start image
      USER ma-user
      
    1. Build an image.

      Run the ma-cli image build command to build an image with the Dockerfile. For more information, see Creating an Image in ModelArts Notebook.

      ma-cli image build .ma/upgrade_current_notebook_apt_packages/Dockerfile -swr notebook-test/my_image:0.0.1 -P XXX

      The Dockerfile is stored in .ma/upgrade_current_notebook_apt_package/Dockerfile and the new image is stored in notebook-test/my_image:0.0.1 in SWR. XXX indicates the profile specified for authentication.