标签:格式 命令 pre author str comm who created 退出
CentOS 7.5
yum install -y docker
systemctl start docker
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
注:对于Docker镜像来说,如果不显式地指定TAG,则默认会选择 latest标签,即下载仓库中最新版本的镜像。
[root@kvm ~]# docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
a02a4930cb5d: Pull complete
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for docker.io/centos:latest docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
a02a4930cb5d: Pull complete
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for docker.io/centos:latest docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
a02a4930cb5d: Pull complete
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for docker.io/centos:latest
注:该命令实际上下载的就是centos:latest镜像,目前最新的7.6.1810版本的镜像。
[root@kvm ~]# docker pull centos:7.3.1611
Trying to pull repository docker.io/library/centos ...
7.3.1611: Pulling from docker.io/library/centos
b8e0383d5f94: Pull complete
Digest: sha256:6fe8d484f2897e2ea75f496bfb6792b539baf3e56880fce3b9b6505d76e266dd
Status: Downloaded newer image for docker.io/centos:7.3.1611
[root@kvm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos latest 1e1148e4cc2c 7 weeks ago 202 MB
docker.io/centos 7.3.1611 1e20acd39495 3 months ago 192 MB
创建镜像的方法主要有三种:基于已有镜像的容器创建、基于本地模板导入、基于Dockerfile创建;这里着重介绍前两种。
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
[root@kvm ~]# docker commit --help
Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Create a new image from a container‘s changes
Options:
-a, --author string 作者信息
-c, --change list 提交的时候执行Dockerfile指令 (default [])
--help 帮助信息
-m, --message string 提交信息
-p, --pause 提交期间暂停容器运行
[root@kvm ~]# docker run -t -i docker.io/centos:7.3.1611 /bin/bash
[root@90d3b762f848 /]# touch test.txt
[root@90d3b762f848 /]# exit
注:记住容器 ID为90d3b762f848。
[root@kvm ~]# docker commit -m "add a file named test.txt" -a "docker new" 90d3b762f848 www.wholj.com:7.3
sha256:3a51b6661c9f9c31ec8239405535cc57f782972f6eedf8452e2d8f4bce0bc2d6
[root@kvm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
www.wholj.com 7.3 3a51b6661c9f 7 seconds ago 192 MB
docker.io/centos latest 1e1148e4cc2c 7 weeks ago 202 MB
docker.io/centos 7.3.1611 1e20acd39495 3 months ago 192 MB
镜像ID为3a51b6661c9f的镜像即为刚新增的。[root@kvm /home/tools/ISO]# docker import --help
Usage: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Import the contents from a tarball to create a filesystem image
Options:
-c, --change list Apply Dockerfile instruction to the created image (default [])
--help 帮助信息
-m, --message string 为此导入镜像设置提交信息
[root@kvm /home/tools/ISO]# cat centos-7-x86_64-minimal.tar.gz | docker import - www.wholj.com:7.5
sha256:4950a54ede5a5c0da704c6f74e6bcc43d440e83260b0752a926325035435a7dc
[root@kvm /home/tools/ISO]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
www.wholj.com 7.5 4950a54ede5a 10 seconds ago 435 MB
www.wholj.com 7.3 3a51b6661c9f 2 days ago 192 MB
docker.io/centos latest 1e1148e4cc2c 7 weeks ago 202 MB
docker.io/centos 7.3.1611 1e20acd39495 3 months ago 192 MB
镜像ID为4950a54ede5a的镜像即为刚新增的。
将本地已有的镜像文件导出后可分享给其他人使用。
docker save [OPTIONS] IMAGE [IMAGE...]
[root@kvm ~]# docker save --help
Usage: docker save [OPTIONS] IMAGE [IMAGE...]
Save one or more images to a tar archive (streamed to STDOUT by default)
Options:
--help 帮助信息
-o, --output string 从标准输出导出镜像到指定的文件中
[root@kvm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
www.wholj.com 7.3 3a51b6661c9f About an hour ago 192 MB
docker.io/centos latest 1e1148e4cc2c 7 weeks ago 202 MB
docker.io/centos 7.3.1611 1e20acd39495 3 months ago 192 MB
[root@kvm ~]# ll
total 8
-rw-------. 1 root root 2090 Nov 30 11:33 anaconda-ks.cfg
-rw-------. 1 root root 1955 Nov 30 11:33 original-ks.cfg
[root@kvm ~]# docker save -o centos_7.6.tar docker.io/centos:latest
[root@kvm ~]# ll
total 205272
-rw-------. 1 root root 2090 Nov 30 11:33 anaconda-ks.cfg
-rw------- 1 root root 210186752 Jan 25 17:17 centos_7.6.tar
-rw-------. 1 root root 1955 Nov 30 11:33 original-ks.cfg
[root@kvm ~]#
将别人分享给自己的镜像导入到本地镜像库。
docker load [OPTIONS]
[root@kvm ~]# docker load --help
Usage: docker load [OPTIONS]
Load an image from a tar archive or STDIN
Options:
--help 帮助信息
-i, --input string 从指定tar文件读入镜像内容
-q, --quiet Suppress the load output
[root@kvm ~]# docker load -i ./centos_7.6.tar
Loaded image: docker.io/centos:latest
或者:
[root@kvm ~]# docker load < ./centos_7.6.tar
Loaded image: docker.io/centos:latest
注:上述命令将导入镜像及其相关的元数据信息(包括标签等)。导入成功后,可以使用docker images命令进行查看,与原镜像一致。
标签:格式 命令 pre author str comm who created 退出
原文地址:https://www.cnblogs.com/wholj/p/10313670.html