Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Creating a Custom Image Using Dockerfile

Updated on 2024-10-29 GMT+08:00

Scenario

This example shows how to use ma-cli commands in ModelArts CLI to create and register a custom image for AI development with a preset PyTorch image. For details, see ma-cli Image Building Command.

Procedure

  1. Create a notebook instance.
  2. Create a custom image in the notebook instance.
  3. Register the image on ModelArts.
  4. Create a notebook instance and verify the new image.

Creating a Notebook Instance

  1. Log in to the ModelArts management console. In the navigation pane on the left, choose Development Workspace > Notebook. On the displayed page, click Create Notebook. Set Image to Public image and select a PyTorch image. Retain the default values for other parameters. For details, see Creating a Notebook Instance.
  2. After the notebook instance is created and in the Running state, locate it in the notebook list, and click Open in the Operation column. On the displayed JupyterLab page, click Terminal.

Creating a Custom Image in a Notebook Instance

  1. Configure authentication information, specify a profile, and enter the account information as prompted. For details, 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 details about the command, see ma-cli Image Building Commands.

      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.

Registering an Image

After an image is created, register it with ModelArts image management so that the image can be used in ModelArts.

Use either of the following methods:

  • Method 1: Run the ma-cli image register command to register an image. Then, the information of the registered image is returned, including image ID and name, as shown in the following figure. For details about the command, see ma-cli Image Building Commands.
    ma-cli image register --swr-path=swr.ap-southeast-1.myhuaweicloud.com/notebook-test/my_image:0.0.1 -P XXX
    Figure 1 Registering an image

  • Method 2: Register the image on the ModelArts management console.

    Log in to the ModelArts management console. In the navigation pane on the left, select Image Management. The Image Management page is displayed.

    1. Click Register. Paste the complete SWR address or click to select a private image from SWR for registration.
    2. Set Architecture and Type based on the site requirements. The values must be those of the image source.

Creating and Using a Notebook Instance

After an image is registered, it is available for development environment creation. You can log in to the ModelArts management console, choose DevEnviron > Notebook, and select the image during creation.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback