本笔记为阿里云天池龙珠计划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
-rw-r--r-- 1 mac staff 647B 9 28 15:36 Dockerfile
-rw-r--r-- 1 mac staff 152B 9 28 15:35 math.py
-rw-r--r-- 1 mac staff 69B 9 28 15:35 run.sh
➜ docker_test01 docker build -t registry.cn-hangzhou.aliyuncs.com/ly_22_test/docker_test01:01 .
[+] Building 1268.4s (4/8)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 691B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for registry.cn-shanghai.aliyuncs.com/tcc-public/pytorch:1.4-cuda10.1-py3 2.6s
=> [1/4] FROM registry.cn-shanghai.aliyuncs.com/tcc-public/pytorch:1.4-cuda10.1-py3@sha256:c612782acc39256aac0637d58d297644066c62f6f84f0b88cfdc335bb25d0d22 1265.7s
=> => resolve registry.cn-shanghai.aliyuncs.com/tcc-public/pytorch:1.4-cuda10.1-py3@sha256:c612782acc39256aac0637d58d297644066c62f6f84f0b88cfdc335bb25d0d22 0.0s
=> => sha256:8c3b70e3904492c753652606df4726430426f42ea56e06ea924d6fea7ae162a1 845B / 845B 0.3s
=> => sha256:76c152fbfd03d74990b2b88dab7d6ce61187e6c80dfb883a734ff109d0b12e78 11.12kB / 11.12kB 0.0s
=> => sha256:7ddbc47eeb70dc7f08e410a6667948b87ff3883024eb41478b44ef9a81bf400c 26.69MB / 26.69MB 118.0s
=> => sha256:c1bbdc448b7263673926b8fe2e88491e5083a8b4b06ddfabf311f2fc5f27e2ff 35.36kB / 35.36kB 0.3s
=> => sha256:c612782acc39256aac0637d58d297644066c62f6f84f0b88cfdc335bb25d0d22 3.47kB / 3.47kB 0.0s
=> => sha256:45d437916d5781043432f2d72608049dcf74ddbd27daa01a25fa63c8f1b9adc4 162B / 162B 0.4s
=> => sha256:d8f1569ddae616589c5a2dabf668fadd250ee9d89253ef16f0cb0c8a9459b322 7.22MB / 7.22MB 29.1s
=> => sha256:85386706b02069c58ffaea9de66c360f9d59890e56f58485d05c1a532ca30db1 8.45MB / 8.45MB 39.8s
=> => sha256:ee9b457b77d047ff322858e2de025e266ff5908aec569560e77e2e4451fc23f4 184B / 184B 29.3s
=> => sha256:be4f3343ecd31ebf7ec8809f61b1d36c2c2f98fc4e63582401d9108575bc443a 266.34MB / 688.74MB 1265.7s
=> => sha256:30b4effda4fdab95ec4eba8873f86e7574c2edddf4dc5df8212e3eda1545aafa 272.63MB / 820.84MB 1265.7s
=> => sha256:b398e882f4149bf61faa8f2c1d47a4fe98b8fe1b2c9379da1d58ddc54fe67cf0 241.17MB / 532.41MB 1265.7s
=> => extracting sha256:7ddbc47eeb70dc7f08e410a6667948b87ff3883024eb41478b44ef9a81bf400c 1.8s
=> => extracting sha256:c1bbdc448b7263673926b8fe2e88491e5083a8b4b06ddfabf311f2fc5f27e2ff 0.1s
=> => extracting sha256:8c3b70e3904492c753652606df4726430426f42ea56e06ea924d6fea7ae162a1 0.0s
=> => extracting sha256:45d437916d5781043432f2d72608049dcf74ddbd27daa01a25fa63c8f1b9adc4 0.0s
=> => extracting sha256:d8f1569ddae616589c5a2dabf668fadd250ee9d89253ef16f0cb0c8a9459b322 0.4s
=> => extracting sha256:85386706b02069c58ffaea9de66c360f9d59890e56f58485d05c1a532ca30db1 0.4s
=> => extracting sha256:ee9b457b77d047ff322858e2de025e266ff5908aec569560e77e2e4451fc23f4 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 292B
➜ docker_test01 docker images;
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/ly_22_test/docker_test01 01 27cc5afec611 3 minutes ago 7.56GB
registry.cn-hangzhou.aliyuncs.com/ly_22_test/test02 03 3267d4dc6495 4 hours ago 2.61GB
test02 02 56e97fc9a4e0 5 hours ago 2.61GB
registry.cn-hangzhou.aliyuncs.com/ly_22_test/test02 02 56e97fc9a4e0 5 hours ago 2.61GB
registry.cn-shanghai.aliyuncs.com/target test f8b80d0635b4 8 hours ago 1.01GB
ubuntu 18.04 35b3f4f76a24 3 weeks ago 63.1MB
registry.cn-hangzhou.aliyuncs.com/ly_22_test/test01 0.1 feb5d9fea6a5 12 months ago 13.3kB
registry.cn-shanghai.aliyuncs.com/tcc-public/pytorch latest-py3 51e0332b751a 3 years ago 2.61GB
➜ docker_test01 docker push registry.cn-hangzhou.aliyuncs.com/ly_22_test/docker_test01:01
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/ly_22_test/docker_test01]
5f70bf18a086: Pushed
a58acffdfc0d: Pushed
a1d0ab32cda4: Pushed
b0643e258249: Pushed
4d64a8bbbc06: Pushed
35ff166c35a9: Pushing [====> ] 222.6MB/2.736GB
c0cb45b106e8: Pushing [==================> ] 405.5MB/1.121GB
486a27d7fdcd: Pushed
1db09913a256: Pushing [==============> ] 247.9MB/833.4MB
2e282f599fd6: Pushing [=========> ] 295.9MB/1.608GB
e6f174f76be4: Pushing [==========> ] 244.4MB/1.119GB
808fd332a58a: Waiting
b16af11cbf29: Waiting
37b9a4b22186: Waiting
e0b3afb09dc3: Waiting
6c01b5a53aac: Waiting
2c6ac8e5063e: Waiting
cc967c529ced: Waiting
此处提交镜像到ack,默认已经提交创建仓库,并登陆到docker中