Step1 制作自定义镜像
本节描述通过加载镜像构建模板并编写Dockerfile,构建出一个新镜像。如下的步骤都需要在“开发环境 > Notebook”的Terminal中完成,请提前创建好开发环境并打开Terminal。关于Dockerfile的具体编写方法,请参考官网。
- 首先配置鉴权信息,指定profile,根据提示输入账号、用户名及密码。鉴权更多信息请查看配置登录信息。
ma-cli configure --auth PWD -P xxx
- 执行env|grep -i CURRENT_IMAGE_NAME命令查询当前实例所使用的镜像。
- 制作新镜像。
- 获取上步查询的基础镜像的SWR地址。
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
- 加载镜像构建模板。
执行ma-cli image get-template命令查询镜像模板。
然后执行ma-cli image add-template命令将镜像模板加载到指定文件夹下,默认路径为当前命令所在的路径。例如:加载upgrade_current_notebook_apt_packages镜像构建模板。
ma-cli image add-template upgrade_current_notebook_apt_packages
- 修改Dockerfile。
本例的Dockerfile将基于PyTorch基础镜像pytorch1.8-cuda10.2-cudnn7-ubuntu18.04进行改造,加载镜像模板upgrade_current_notebook_apt_packages,升级gcc和g++。
加载镜像模板后,Dockerfile文件自动加载,在“.ma/upgrade_current_notebook_apt_packages”路径下,内容参考如下,根据实际需求修改:
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
- 构建镜像
使用ma-cli image build命令从Dockerfile构建出一个新镜像。命令更多信息请参考镜像构建命令。
ma-cli image build .ma/upgrade_current_notebook_apt_packages/Dockerfile -swr notebook-test/my_image:0.0.1 -P XXX
其中“.ma/upgrade_current_notebook_apt_package/Dockerfile”为Dockerfile文件所在路径,“notebook-test/my_image:0.0.1”为构建的新镜像的SWR路径。“XXX”为鉴权时指定的profile。
- 获取上步查询的基础镜像的SWR地址。