本笔记为阿里云天池龙珠计划Docker训练营的学习内容,链接为:https://tianchi.aliyun.com/specials/activity/promotion/aicampdocker;
➜ testv0928 mkdir docker_test01
➜ testv0928 cd docker_test01
使用ack账号登陆docker
➜ docker_test01 docker login --username=**** registry.cn-hangzhou.aliyuncs.com
Password:
Login Succeeded
Logging in with your password grants your terminal complete access to your account.
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/
➜ docker_test01 vim math.py
➜ docker_test01 vim run.sh
➜ docker_test01 cat math.py
import torch
device = torch.device("cuda")
a = torch.randn(3, 3)
b = torch.randn(3, 3)
a = a.to(device)
b = b.to(device)
c = torch.matmul(a,b)
print(c)
➜ docker_test01 cat run.sh
#bin/bash
#打印GPU信息
nvidia-smi
#执行math.py
python3 math.py
➜ docker_test01 vim Dockerfile
➜ docker_test01 cat Dockerfile
# Base Images
## 从天池基础镜像构建(from的base img 根据自己的需要更换,建议使用天池open list镜像链接:https://tianchi.aliyun.com/forum/postDetail?postId=67720)
FROM registry.cn-shanghai.aliyuncs.com/tcc-public/pytorch:1.4-cuda10.1-py3
##安装依赖包,pip包请在requirements.txt添加
#RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
## 把当前文件夹里的文件构建到镜像的//workspace目录下,并设置为默认工作目录
ADD math.py /workspace
ADD run.sh /workspace
WORKDIR /workspace
## 镜像启动后统一执行 sh run.sh
CMD ["sh", "run.sh"]
➜ docker_test01 docker build -t registry.cn-hangzhou.aliyuncs.com/ly_22_test/docker_test01:01
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
➜ docker_test01 ls
Dockerfile math.py run.sh
➜ docker_test01 ll
total 24