1.创建容器
1)docker pull 从镜像仓库拉取镜像
[root@localhost docker]# docker pull nginx:1.14
1.14: Pulling from library/nginx
27833a3ba0a5: Pull complete
0f23e58bd0b7: Pull complete
8ca774778e85: Pull complete
Digest: sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Status: Downloaded newer image for nginx:1.14
docker.io/library/nginx:1.14
2)docker push 推送镜像到镜像仓库
3)docker images 列出镜像,效果等同于docker image ls
4)docker inspect 查看一个镜像的详情
[root@localhost docker]# docker image inspect nginx:1.14
[
{
"Id": "sha256:295c7be079025306c4f1d65997fcf7adb411c88f139ad1d34b537164aa060369",
"RepoTags": [
"nginx:1.14"
],
"RepoDigests": [
"nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d"
],
"Parent": "",
"Comment": "",
"Created": "2019-03-26T23:14:52.227945051Z",
"Container": "5e8d96e0fb01832974f0680a9aff2fbadc37fcf30447ae30e19f59b926672041",
"ContainerConfig": {
"Hostname": "5e8d96e0fb01",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.14.2-1~stretch",
"NJS_VERSION=1.14.2.0.2.6-1~stretch"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"nginx\" \"-g\" \"daemon off;\"]"
],
"ArgsEscaped": true,
"Image": "sha256:ac539667b75fa925232b8dbbfdfb8adb98007c44e11a5fbd4001916c0fcc0bd4",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers "
},
"StopSignal": "SIGTERM"
},
"DockerVersion": "18.06.1-ce",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.14.2-1~stretch",
"NJS_VERSION=1.14.2.0.2.6-1~stretch"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"ArgsEscaped": true,
"Image": "sha256:ac539667b75fa925232b8dbbfdfb8adb98007c44e11a5fbd4001916c0fcc0bd4",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers "
},
"StopSignal": "SIGTERM"
},
"Architecture": "amd64",
"Os": "linux",
"Size": 109129446,
"VirtualSize": 109129446,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/d9d25b8bbde55606612c08785334355da6737e8acd0bc19cfdeb96a13451349d/diff:/var/lib/docker/overlay2/2c91d73ff17d4c440aa6402db9fbf09f3db70919fae33a241eb61ed3cb9fcc7b/diff",
"MergedDir": "/var/lib/docker/overlay2/1777cc67e8f61946fc9e001c6182fbfda8d9ecd425217e713597565906dbfdd5/merged",
"UpperDir": "/var/lib/docker/overlay2/1777cc67e8f61946fc9e001c6182fbfda8d9ecd425217e713597565906dbfdd5/diff",
"WorkDir": "/var/lib/docker/overlay2/1777cc67e8f61946fc9e001c6182fbfda8d9ecd425217e713597565906dbfdd5/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:5dacd731af1b0386ead06c8b1feff9f65d9e0bdfec032d2cd0bc03690698feda",
"sha256:b8f18c3b860b067be09836beadd676a0aa1e784ec28cf730986859b4146c344a",
"sha256:82ae01d5004e2143b642b1a008624e7521c73ab18e5776a22f18a172b9dbec80"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
5)docker image rm 删除镜像
[root@localhost docker]# docker image rm nginx:1.14
Untagged: nginx:1.14
Untagged: nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Deleted: sha256:295c7be079025306c4f1d65997fcf7adb411c88f139ad1d34b537164aa060369
Deleted: sha256:19606512dfe192788a55d7c1efb9ec02041b4e318587632f755c5112f927e0e3
Deleted: sha256:0b83495b3ad3db8663870c3babeba503a35740537a5e25acdf61ce6a8bdad06f
Deleted: sha256:5dacd731af1b0386ead06c8b1feff9f65d9e0bdfec032d2cd0bc03690698feda
6)docker tag 引用源镜像、创建带有特定标记的目标镜像,也可以用 docker image tag
[root@localhost docker]# docker image tag nginx:1.14 nginx:test1.14
[root@localhost docker]#
[root@localhost docker]# docker tag nginx:1.14 nginx:test1.14_2
[root@localhost docker]#
[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest db8ee88ad75f 2 weeks ago 1.22MB
nginx 1.14 295c7be07902 4 months ago 109MB
nginx test1.14 295c7be07902 4 months ago 109MB
nginx test1.14_2 295c7be07902 4 months ago 109MB
hello-world latest fce289e99eb9 7 months ago 1.84kB
[root@localhost docker]#
7)docker image save 导出镜像,所有层的信息都会保存
导出镜像:docker image save nginx:test > nginx_test.tar
导入镜像:docker load < nginx_test.tar 或 docker load -i nginx_test.tar
[root@localhost docker]# docker image save nginx:test > nginx_test.tar
[root@localhost docker]# du -sh nginx_test.tar
124M nginx_test.tar
[root@localhost docker]# ls -lh nginx_test.tar
-rw-r--r--. 1 root root 124M Aug 8 23:38 nginx_test.tar
[root@localhost docker]#
[root@localhost docker]# docker image rm nginx:test
Untagged: nginx:test
[root@localhost docker]#
[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest e445ab08b2be 2 weeks ago 126MB
busybox latest db8ee88ad75f 2 weeks ago 1.22MB
hello-world latest fce289e99eb9 7 months ago 1.84kB
[root@localhost docker]# docker load < nginx_test.tar
Loaded image: nginx:test
[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest e445ab08b2be 2 weeks ago 126MB
nginx test e445ab08b2be 2 weeks ago 126MB
busybox latest db8ee88ad75f 2 weeks ago 1.22MB
hello-world latest fce289e99eb9 7 months ago 1.84kB
8)docker export 导出文件系统,针对容器操作
导出:docker export 9c596c9dba88 > busybox.tar
导入:docker image import busybox.tar busybox:self
[root@localhost docker]# docker export 9c596c9dba88 > busybox.tar
[root@localhost docker]# du -sh busybox.tar
1.4M busybox.tar
[root@localhost docker]# docker image import busybox.tar
sha256:8ed5b2a1e4b6f3cf17d3a3b15829b4ba53cf6b03b50708bbe6e9a24409cd1e07
[root@localhost docker]#
[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
8ed5b2a1e4b6 21 seconds ago 1.22MB
nginx latest e445ab08b2be 2 weeks ago 126MB
nginx test e445ab08b2be 2 weeks ago 126MB
busybox latest db8ee88ad75f 2 weeks ago 1.22MB
hello-world latest fce289e99eb9 7 months ago 1.84kB
[root@localhost docker]#
[root@localhost docker]# docker image import busybox.tar busybox:self
sha256:aff42504dc67f47180e98b52225c7c8e2376a9a3629cfc3ee5437036bb2967ec
[root@localhost docker]#
[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox self aff42504dc67 4 seconds ago 1.22MB
8ed5b2a1e4b6 About a minute ago 1.22MB
nginx latest e445ab08b2be 2 weeks ago 126MB
nginx test e445ab08b2be 2 weeks ago 126MB
busybox latest db8ee88ad75f 2 weeks ago 1.22MB
hello-world latest fce289e99eb9 7 months ago 1.84kB
[root@localhost docker]#
docker load 和 doacker import 的区别可参考 -> https://www.cnblogs.com/Cherry-Linux/p/8025777.html