某项目中,想把昇腾芯片的一个算法demo放到ModelArts的环境上运行,于是制作一个镜像,下面简单记录下步骤。

1安装Docker,可参考Docker官方文档。可参考以下方式安装docker

curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh

2获取基础镜像,这里以centos7.6为例

首先搜索一下有哪些centos镜像版本,结果报错

[root@localhost self-define-images]# docker search centos:7.6
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

 说明docker没有启动,于是

[root@localhost self-define-images]# systemctl start docker
[root@localhost self-define-images]# docker search centos:7.6
NAME                                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
xuwenfeng1225/centos7_jdk8                     build in centos:7.6.1810 and jdk1.8.0_211       0                    
how2j/centos7_tools                            centos:7.6.1810  + iproute ftp bind-utils ne…   0                    
how2j/centos7_tools_ftp                        centos:7.6.1810  + iproute ftp bind-utils ne…   0                    
zyfxgary/bigdata-base                          centos centos:7.6.1810  bigdata-base:v1         0                    
how2j/centos7_tools_ftp_java_tomcat8           centos:7.6.1810  + iproute ftp bind-utils ne…   0                    
how2j/centos7_tools_ftp_java_mysql55           centos:7.6.1810  + iproute ftp bind-utils ne…   0                    
how2j/centos7_tools_ftp_java_tomcat7           centos:7.6.1810  + iproute ftp bind-utils ne…   0                    
how2j/centos7_tools_ftp_java                   centos:7.6.1810  + iproute ftp bind-utils ne…   0                    
how2j/centos7_tools_ftp_java_mysql55_tomcat7   centos:7.6.1810  + iproute ftp bind-utils ne…   0                    
how2j/centos7_tools_ftp_java_mysql55_tomcat8   centos:7.6.1810  + iproute ftp bind-utils ne…   0                    
sixteen16/centos7-php7-swoole4                 centos:7.6.1810 / PHP 7.3.12 / SWOOLE 4.4.17…   0    

 然后pull镜像

docker pull centos:7.6.1810

用上面的命令提示找不到,我直接

docker pull centos

3编写Dockfile文件

Dockfile文件内容如下

From centos:latest
# 配置华为云的源,安装 python、python3-pip 和 Flask
#RUN cp -a /etc/apt/sources.list /etc/apt/sources.list.bak && \
#  sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list && \
#  sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list && \

# 拷贝应用服务代码进镜像里面
COPY hello_world  /opt/

# 指定镜像的启动命令
#CMD python3  /opt/test_app.py

4构建自定义镜像“test:v1”

docker build -t test:v1 .

5 查看创建的自定义镜像

[root@localhost self-define-images]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
test         v1        5f76ff53eb4d   12 minutes ago   272MB
centos       latest    e6a0117ec169   12 months ago    272MB

参考文献:使用自定义镜像创建AI应用_AI开发平台ModelArts_最佳实践_推理部署_华为云

 

Logo

昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链

更多推荐