1、获取镜像
1 | docker pull ubuntu:16.04 |
---|
使用docker import
导入镜像
1 2 3 4 | [root@xs_test01 ~]# docker import http://download.openvz.org/template/precreated/ubuntu-14.04-x86_64-minimal.tar.gz openvz/ubuntu:14.04 Downloading from http://download.openvz.org/template/precreated/ubuntu-14.04-x86_64-minimal.tar.gz Importing [==================================================>] 78.42MB/78.42MB sha256:4fb9933d51b0b143949c1cb1ba661b58bd418c47154053c77e03d78eb66be0ce |
---|
2、运行镜像
1 2 3 4 5 | docker run -it --rm ubuntu:16.04 bash -it:这是两个参数,-i代表交互式操作,-t代表终端 --rm代表容器退出后随之删除,默认情况下,为了排障需求,退出的容器并不会立即删除,除非手动docker rm ubuntu:16.04代表使用此镜像作为基础来启动容器 bash:一种交互式shell |
---|
3、列出镜像
1 2 3 4 5 6 7 8 9 10 | docker image ls 列出顶层镜像,或者使用docker images docker image ls -a 列出所有镜像,包括中间层镜像 docker image ls ubuntu 列出部分镜像 docker image ls -f label=v=0.1 如果定义了label,可以根据label来过滤 docker image ls -f since=mongo:3.2 列出在mongo:3.2之后的镜像,列出之前的镜像可以用before docker image ls -q 列出ID列表 docker image ls --format "{{.ID}}: {{.Repository}}" 结果为: 5f515359c7f8: redis 05a60462f8ba: nginx fe9198c04d62: mongo |
---|
4、查看镜像、容器、数据卷所占用的空间大小
1 | docker system df |
---|
5、删除本地镜像
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 命令格式: docker image rm [选项] <镜像1> [<镜像2> ...] 用ID、镜像名、摘要删除镜像 例如: $ docker image ls REPOSITORY TAG IMAGEID CREATED SIZE centos latest 0584b3d2cf6d 3 weeks ago 196.5 MB redis alpine 501ad78535f0 3 weeks ago 21.03 MB docker latest cf693ec9b5c7 3 weeks ago 105.1 MB nginx latest e43d811ce2f4 5 weeks ago 181.5 MB 1)可以用镜像的完整ID,也就是长ID来删除镜像,docker image ls 默认列出的就是短ID docker image rm 0584b3d2cf6d 删除centos这个镜像 2)可以用镜像名,也就是<仓库名>:<标签>来删除镜像 docker image rm centos 3)最准确的是使用镜像摘要来删除镜像 docker image ls --digests REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE hello-world latest sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7 f2a91732366c 3 months ago 1.85kB docker image rm node@sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7 |
---|
6、查看镜像历史情况
1 2 3 | [root@xs_test01 ~]# docker history openvz/ubuntu:14.04 IMAGE CREATED CREATED BY SIZE COMMENT 4fb9933d51b0 3 minutes ago 215MB Imported from http://download.openvz.org/template/precreated/ubuntu-14.04-x86_64-minimal.tar.gz |
---|
7、保存镜像
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@xs_test01 ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE openvz/ubuntu 14.04 4fb9933d51b0 8 minutes ago 215MB entrypoint latest 10c7252261f8 8 days ago 4.82MB myip latest 7f77fc2f30b7 8 days ago 307MB nginx v3 7386045ee352 8 days ago 109MB nginx v2 ada0bc75fda7 8 days ago 109MB nginx latest e548f1a579cf 3 weeks ago 109MB redis latest 33c26d72bd74 3 weeks ago 107MB alpine 3.4 c7fc7faf8c28 2 months ago 4.82MB centos latest ff426288ea90 2 months ago 207MB hello-world latest f2a91732366c 3 months ago 1.85kB [root@xs_test01 ~]# docker save myip | gzip > myip_`date %Y%m%d`.tar.gz [root@xs_test01 ~]# ll -rw-r--r-- 1 root root 107207689 3月 14 09:38 myip_20180314.tar.gz |
---|
copy到其他机器上
1 2 3 4 5 6 7 8 9 10 | [root@xs_test03 docker]# docker load -i myip_20180314.tar.gz e15afa4858b6: Loading layer [==================================================>] 215.8 MB/215.8 MB d7824218c605: Loading layer [==================================================>] 99.79 MB/99.79 MB Loaded image: myip:latest 查看镜像 [root@xs_test03 docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE myip latest 7f77fc2f30b7 8 days ago 306.8 MB docker.io/centos 6 609c1f9b5406 9 weeks ago 194.5 MB docker.io/hello-world latest f2a91732366c 3 months ago 1.848 kB |
---|