創建鏡像
阿新 • • 發佈:2018-07-24
com template rec from ted test 模板 當前 adb 創建鏡像的方法有三種,1、基於已有的鏡像的容器創建;2、基於本地模板導入;3、基於dockerfile文件創建。
1、基於已有鏡像的容器創建:
使用docker commit命令,命令格式為docker commit 【options】container [repostory[:tag]]
1、基於已有鏡像的容器創建:
使用docker commit命令,命令格式為docker commit 【options】container [repostory[:tag]]
示例:
root@renkailang-K43SV:/home/renkailang# docker run -dit centos /bin/bash fc72541bad7eb5430c28d06f6da6724bbeaa864f1e08474e97dc8b417f32ff61 root@renkailang-K43SV:/home/renkailang# docker commit fc7254 myrepo:v1 sha256:fad1b5fcac3d9efbde62cc8366e515993c3ced83b6fd7a1bfa4af65d2e3433a4
查看新提交的鏡像:
root@renkailang-K43SV:/home/renkailang# docker images REPOSITORY TAG IMAGE ID CREATED SIZE myrepo v1 fad1b5fcac3d About a minute ago 200MB centos latest 49f7960eb7e4 6 weeks ago 200MB
2、通過本地模板導入鏡像
可以使用openvz提供的模板,通過URL在線創建:
root@renkailang-K43SV:/home/renkailang# docker import https://download.openvz.org/template/precreated/debian-7.0-x86-minimal.tar.gz debian:v2 Downloading from https://download.openvz.org/template/precreated/debian-7.0-x86-minimal.tar.gz sha256:62e8d3459bb271c5e3496b264f34d4baaa322b66870270cade16645425a932cfB/88.44MB
或者 ,通過本地文件導入:
root@renkailang-K43SV:/home/renkailang# ls
debian-7.0-x86-minimal.tar.gz
root@renkailang-K43SV:/home/renkailang# docker import debian-7.0-x86-minimal.tar.gz debian:v3
sha256:33e16d28c5c9828ab9d7745ee082a4eb35fadb50487fd742252a3ed02be91181
3、保存和加載鏡像:
查看當前鏡像:
root@renkailang-K43SV:/home/renkailang# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos v2 1b6231b7505a 2 minutes ago 288MB
保存當前鏡像到tar文件:
root@renkailang-K43SV:/home/renkailang# docker save -o centosv3.tar centos:v2
root@renkailang-K43SV:/home/renkailang# ls
centosv3.tar debian-7.0-x86-minimal.tar.gz
載入tar文件到鏡像:
root@renkailang-K43SV:/home/renkailang# docker load -i centosv3.tar
創建鏡像