上一篇:Docker
相关知识《Docker
安装》
TAG
,则默认使用latest
作为TAG
,如果省略REGISTRY
,则默认使用registry.hub.docker.com
作为REGISTRY
$ docker pull [REGISTRY/]NAME[:TAG]
ubuntu:14.04
,这应该使用如下命令:$ docker pull hub.c.163.com/public/ubuntu:14.04
TAG
,则默认使用latest
作为TAG
,如果省略REGISTRY
,则默认使用registry.hub.docker.com
作为REGISTRY
$ docker push NAME[:TAG] | [REGISTRY_HOST[:REGISTRY_PORT]/]NAME[:TAG]
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
a75a1a2f7c7c 39 minutes ago 81.4MB
daocloud.io/library/redis latest b6dddb991dfa 2 weeks ago 107MB
openjdk 8-jre-alpine e2f6fe2dacef 3 weeks ago 81.4MB
daocloud.io/library/tomcat 8.0.45-jre7 fa6ad595ba45 2 months ago 357MB
mytomcat 8.0 fa6ad595ba45 2 months ago 357MB
daocloud.io/daocloud/daocloud-toolset latest bbdc71e950ea 6 months ago 147MB
images
子命令主要支持如下选项:
-a,--all=true|false
:列出所有的镜像文件(包括临时文件),默认为false
;
--digests=true|false
:列出镜像的数字摘要值,默认为false
--f,--filter=[ ]
:过滤列出的镜像,如dangling=true
只显示没有被使用的镜像; 如:
$ sudo docker images -f dangling=true
REPOSITORY TAG IMAGE ID CREATED SIZE
a75a1a2f7c7c About an hour ago 81.4MB
或者
$ sudo docker images --filter=dangling=true
REPOSITORY TAG IMAGE ID CREATED SIZE
a75a1a2f7c7c About an hour ago 81.4MB
--format="TEMPLATE"
:控制输出格式
TEMPLATE
说明:
.ID ----> Image ID
.Repository ----> Image repository
.Tag ----> Image tag
.Digest ----> Image digest
.CreatedSince ----> Elapsed time since the image was created
.CreatedAt ---->Time when the image was created
.Size ----> Image disk size
$ sudo docker images --format "{{.ID}}:{{.Repository}}"
a75a1a2f7c7c:
b6dddb991dfa: daocloud.io/library/redis
e2f6fe2dacef: openjdk
fa6ad595ba45: daocloud.io/library/tomcat
fa6ad595ba45: mytomcat
bbdc71e950ea: daocloud.io/daocloud/daocloud-toolset
--no-trunc=true|false
:对输出结果中太长的部分是否进截断,默认为true
--quiet,-q=true|false
:仅输出ID
信息,默认为false
其中,对输出结果进行控制的选项如-f,--filter=[]、--no-trunc=true|false、--quiet=true|false
等,大部分命令都支持
tag
命令添加镜像标签$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
a75a1a2f7c7c 9 hours ago 81.4MB
daocloud.io/library/redis latest b6dddb991dfa 2 weeks ago 107MB
openjdk 8-jre-alpine e2f6fe2dacef 3 weeks ago 81.4MB
daocloud.io/library/tomcat 8.0.45-jre7 fa6ad595ba45 2 months ago 357MB
daocloud.io/daocloud/daocloud-toolset latest bbdc71e950ea 6 months ago 147MB
$ sudo docker tag daocloud.io/library/tomcat:8.0.45-jre7 mytomcat:8.0
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
a75a1a2f7c7c 9 hours ago 81.4MB
daocloud.io/library/redis latest b6dddb991dfa 2 weeks ago 107MB
openjdk 8-jre-alpine e2f6fe2dacef 3 weeks ago 81.4MB
mytomcat 8.0 fa6ad595ba45 2 months ago 357MB
daocloud.io/library/tomcat 8.0.45-jre7 fa6ad595ba45 2 months ago 357MB
daocloud.io/daocloud/daocloud-toolset latest bbdc71e950ea 6 months ago 147MB
之后可以使用mytomcat:8.0
来表示这个镜像了。
注:mytomcat:8.0
镜像ID
和daocloud.io/library/tomcat:8.0.45-jre7
的ID
完全一致。它们实际上指向的同一个镜像文件,只是别名不同而已,ID
是区分唯一镜像的标志
inspect
命令查看详细信息$ sudo docker inspect mytomcat:8.0
[
{
"Id": "sha256:fa6ad595ba4524f6ce55719626f4f72633d63bb744e3f0631812f80798e6f7ad",
"RepoTags": [
"daocloud.io/library/tomcat:8.0.45-jre7",
"mytomcat:8.0"
],
"RepoDigests": [
"daocloud.io/library/tomcat@sha256:08132ab8b2c606cfb78a0ef9e80e1e724331cab10058135b475f23c032738350"
],
"Parent": "",
"Comment": "",
"Created": "2017-08-09T21:56:15.155320011Z",
"Container": "66dfcd1683cae66a1c660db93034843135655fde732252794e9c39577c216f7e",
"ContainerConfig": {
"Hostname": "e24d0b5cccc1",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/tomcat/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"JAVA_HOME=/docker-java-home/jre",
"JAVA_VERSION=7u131",
"JAVA_DEBIAN_VERSION=7u131-2.6.9-2~deb8u1",
"CATALINA_HOME=/usr/local/tomcat",
"TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib",
"LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib",
"OPENSSL_VERSION=1.1.0f-3",
"GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23",
"TOMCAT_MAJOR=8",
"TOMCAT_VERSION=8.0.45",
"TOMCAT_TGZ_URL=https://www.apache.org/dyn/closer.cgi?action=download&filename=tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz",
"TOMCAT_ASC_URL=https://www.apache.org/dist/tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz.asc",
"TOMCAT_TGZ_FALLBACK_URL=https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz",
"TOMCAT_ASC_FALLBACK_URL=https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz.asc"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"catalina.sh\" \"run\"]"
],
"ArgsEscaped": true,
"Image": "sha256:8f0d0e846f82a1053881fdcc194e302356e2b9f3ffed8d66c05f396cb28c0567",
"Volumes": null,
"WorkingDir": "/usr/local/tomcat",
"Entrypoint": null,
"OnBuild": [],
"Labels": {}
},
"DockerVersion": "17.03.2-ce",
"Author": "",
"Config": {
"Hostname": "e24d0b5cccc1",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/tomcat/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"JAVA_HOME=/docker-java-home/jre",
"JAVA_VERSION=7u131",
"JAVA_DEBIAN_VERSION=7u131-2.6.9-2~deb8u1",
"CATALINA_HOME=/usr/local/tomcat",
"TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib",
"LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib",
"OPENSSL_VERSION=1.1.0f-3",
"GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23",
"TOMCAT_MAJOR=8",
"TOMCAT_VERSION=8.0.45",
"TOMCAT_TGZ_URL=https://www.apache.org/dyn/closer.cgi?action=download&filename=tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz",
"TOMCAT_ASC_URL=https://www.apache.org/dist/tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz.asc",
"TOMCAT_TGZ_FALLBACK_URL=https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz",
"TOMCAT_ASC_FALLBACK_URL=https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz.asc"
],
"Cmd": [
"catalina.sh",
"run"
],
"ArgsEscaped": true,
"Image": "sha256:8f0d0e846f82a1053881fdcc194e302356e2b9f3ffed8d66c05f396cb28c0567",
"Volumes": null,
"WorkingDir": "/usr/local/tomcat",
"Entrypoint": null,
"OnBuild": [],
"Labels": {}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 356933519,
"VirtualSize": 356933519,
"GraphDriver": {
"Data": null,
"Name": "aufs"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:2c40c66f7667aefbb18f7070cf52fae7abbe9b66e49b4e1fd740544e7ceaebdc",
"sha256:654f45ecb7e3a022dd1a10bf47b348b820659e8d9915d87faae403b0b9705b0d",
"sha256:d0d8c46b77680e6111efb775b2ae83f41ba5ca58a828d375fd96c40017bb12b2",
"sha256:1d63bf83c52ac2c3c95721a22c9b208c9f09d6e2a67cbbb893c20b980dcb3527",
"sha256:f7ffae5fc3980f685c86ca07dd04217d8f525af7eea2957e76386c1278818480",
"sha256:f2b7296f00b01d81ae164787d57c6bb614720f2247064e5a90f220b93cedf608",
"sha256:d9fbd1b4d993bdd170d8725ef46628e88121036facfc154e938e88389db1f192",
"sha256:4b9f0d739b0242cabf76cb623e50f26310a337ab75f28c1eafac74027899f53c",
"sha256:baef051a7a538e04747030285ea3460d02f189e941f9c1cfffd82700155c6a7e",
"sha256:0ae16007685280bdbf9f7152d800922f9ee22a0fd89943772e18b1022bc17270",
"sha256:bdbc82086a34182819d4a0e2d1290e76dc3aa79f92cc8c296edcf6493aba6871",
"sha256:939fce81cd1286bbb2b8ec3d7700f9e3cf1a0cf7cb53f3cbc714846496f7ed24"
]
}
}
]
返回的是一个JSON
格式的消息,这些项是该镜像的基本信息,如果只要其中一项,可以使用参数-f
来指定,如:
$ sudo docker inspect mytomcat:8.0 -f {{".ID"}}
sha256:fa6ad595ba4524f6ce55719626f4f72633d63bb744e3f0631812f80798e6f7ad
使用history
命令查看镜像命令历史
$ sudo docker history mytomcat:8.0
IMAGE CREATED CREATED BY SIZE COMMENT
fa6ad595ba45 2 months ago /bin/sh -c #(nop) CMD ["catalina.sh" "run"] 0B
2 months ago /bin/sh -c #(nop) EXPOSE 8080/tcp 0B
2 months ago /bin/sh -c set -e && nativeLines="$(catal... 0B
2 months ago /bin/sh -c set -x && { wget -O tomcat.... 16.4MB
2 months ago /bin/sh -c #(nop) ENV TOMCAT_ASC_FALLBACK... 0B
2 months ago /bin/sh -c #(nop) ENV TOMCAT_TGZ_FALLBACK... 0B
2 months ago /bin/sh -c #(nop) ENV TOMCAT_ASC_URL=http... 0B
2 months ago /bin/sh -c #(nop) ENV TOMCAT_TGZ_URL=http... 0B
2 months ago /bin/sh -c #(nop) ENV TOMCAT_VERSION=8.0.45 0B
2 months ago /bin/sh -c #(nop) ENV TOMCAT_MAJOR=8 0B
2 months ago /bin/sh -c set -ex; for key in $GPG_KEYS;... 128kB
2 months ago /bin/sh -c #(nop) ENV GPG_KEYS=05AB331109... 0B
2 months ago /bin/sh -c apt-get update && apt-get insta... 7.58MB
2 months ago /bin/sh -c set -ex; if ! grep -q stretch ... 164B
2 months ago /bin/sh -c #(nop) ENV OPENSSL_VERSION=1.1... 0B
2 months ago /bin/sh -c #(nop) ENV LD_LIBRARY_PATH=/us... 0B
2 months ago /bin/sh -c #(nop) ENV TOMCAT_NATIVE_LIBDI... 0B
2 months ago /bin/sh -c #(nop) WORKDIR /usr/local/tomcat 0B
2 months ago /bin/sh -c mkdir -p "$CATALINA_HOME" 0B
2 months ago /bin/sh -c #(nop) ENV PATH=/usr/local/tom... 0B
2 months ago /bin/sh -c #(nop) ENV CATALINA_HOME=/usr/... 0B
2 months ago /bin/sh -c set -ex; if [ ! -d /usr/share... 164MB
2 months ago /bin/sh -c #(nop) ENV JAVA_DEBIAN_VERSION... 0B
2 months ago /bin/sh -c #(nop) ENV JAVA_VERSION=7u131 0B
2 months ago /bin/sh -c #(nop) ENV JAVA_HOME=/docker-j... 0B
2 months ago /bin/sh -c ln -svT "/usr/lib/jvm/java-7-op... 33B
2 months ago /bin/sh -c { echo '#!/bin/sh'; echo 's... 87B
2 months ago /bin/sh -c #(nop) ENV LANG=C.UTF-8 0B
2 months ago /bin/sh -c apt-get update && apt-get insta... 1.11MB
2 months ago /bin/sh -c set -ex; if ! command -v gpg >... 0B
2 months ago /bin/sh -c apt-get update && apt-get insta... 44.6MB
2 months ago /bin/sh -c #(nop) CMD ["bash"] 0B
2 months ago /bin/sh -c #(nop) ADD file:a023a99f7d01868... 123MB
$ sudo docker search --automated -s 3 nginx
Flag --automated has been deprecated, use --filter=is-automated=true instead
Flag --stars has been deprecated, use --filter=stars=3 instead
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 1137 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 453 [OK]
jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as... 230 [OK]
webdevops/php-nginx Nginx with PHP-FPM 90 [OK]
bitnami/nginx Bitnami nginx Docker Image 37 [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 16 [OK]
tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 11 [OK]
wodby/drupal-nginx Nginx for Drupal 9 [OK]
webdevops/nginx Nginx container 8 [OK]
blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 7 [OK]
1science/nginx Nginx Docker images that include Consul Te... 4 [OK]
nginxdemos/hello NGINX webserver that serves a simple page ... 3 [OK]
search
支持的参数主要包括:
--automated=true|false
:仅显示自动创建的镜像,默认为false
--no-trunc=true|false
:输出信息不截断信息,默认为false
-s,--stars=X
:指定仅显示评价为指定星级以上的镜像,默认为0,即输出所有镜像docker rmi
命令可以删除镜像docker rmi IMAGE [IMAGE...]
,其中IMAGE
可以为标签或ID
$ sudo docker rmi mytomcat:8.0
Untagged: mytomcat:8.0
当一个镜像有多个标签的时候,docker rmi
命令只是删除该镜像多个标签中的指定标签而已,并不影响镜像文件,当镜像只剩下一个标签的时候,使用docker rmi
命令会彻底删掉镜像,会删除仅该镜像使用的layer
,不会删除该镜像和其他镜像公用的layer
docker commit [OPTIONS] CONTAINER [RESPOSITORY/[:TAG]]
,主要命令参数包括:-a,--author=""
:作者信息-c,--change=[]
:提交的时候执行Dockerfile
指令,包括CMD|ENTERYPOINT|EVN|EXPOSE|LABEL|ONBUILD|USER|VOLUME|WORKDIR
等-m,--message=""
:提交信息-p,--pause=true
:提交时暂停容器运行$ sudo docker run -it mytomcat:8.0 bash root@33dde2b6fbcb:/usr/local/tomcat# touch test
$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 33dde2b6fbcb mytomcat:8.0 "bash" 29 minutes ago Up 29 minutes 8080/tcp xenodochial_snyder
ID
为33dde2b6fbcb
$ sudo docker commit -m "Add a new test file" -a "Docker tester" 33dde2b6fbcb mytomcat-test:0.1 sha256:36593e22f76fe3a47eb24e137af05a5adc2772084fce9bb54342f0297f547120
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE mytomcat-test 0.1 36593e22f76f 19 seconds ago 357MB a75a1a2f7c7c 10 hours ago 81.4MB daocloud.io/library/redis latest b6dddb991dfa 2 weeks ago 107MB openjdk 8-jre-alpine e2f6fe2dacef 3 weeks ago 81.4MB daocloud.io/library/tomcat 8.0.45-jre7 fa6ad595ba45 2 months ago 357MB mytomcat 8.0 fa6ad595ba45 2 months ago 357MB daocloud.io/daocloud/daocloud-toolset latest bbdc71e950ea 6 months ago 147MB
docker import [OPTIONS] file | URL | - [REPOSITORY/[:TAG]]
OpenVZ
提供的模板来创建,或者用其他已经导出的镜像来创建。OPENVZ模板下载(快速通道)$ cat ubuntu-14.04-x86_64-minimal.tar.gz | sudo docker import - ubuntu:14.04
docker save
和 docker load
来存出和载入镜像$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mytomcat-test 0.1 36593e22f76f 3 hours ago 357MB
a75a1a2f7c7c 14 hours ago 81.4MB
daocloud.io/library/redis latest b6dddb991dfa 2 weeks ago 107MB
openjdk 8-jre-alpine e2f6fe2dacef 3 weeks ago 81.4MB
daocloud.io/library/tomcat 8.0.45-jre7 fa6ad595ba45 2 months ago 357MB
mytomcat 8.0 fa6ad595ba45 2 months ago 357MB
daocloud.io/daocloud/daocloud-toolset latest bbdc71e950ea 6 months ago 147MB
$ sudo docker save -o mytomcat-test1.tar mytomcat-test:0.1
$ ls
mytomcat-test1.tar test tomcat8.history
$ sudo docker rmi mytomcat-test:0.1
Untagged: mytomcat-test:0.1
Deleted: sha256:36593e22f76fe3a47eb24e137af05a5adc2772084fce9bb54342f0297f547120
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
a75a1a2f7c7c 14 hours ago 81.4MB
daocloud.io/library/redis latest b6dddb991dfa 2 weeks ago 107MB
openjdk 8-jre-alpine e2f6fe2dacef 3 weeks ago 81.4MB
daocloud.io/library/tomcat 8.0.45-jre7 fa6ad595ba45 2 months ago 357MB
mytomcat 8.0 fa6ad595ba45 2 months ago 357MB
daocloud.io/daocloud/daocloud-toolset latest bbdc71e950ea 6 months ago 147MB
$ sudo docker load --input mytomcat-test1.tar
Loaded image: mytomcat-test:0.1
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mytomcat-test 0.1 36593e22f76f 4 hours ago 357MB
a75a1a2f7c7c 14 hours ago 81.4MB
daocloud.io/library/redis latest b6dddb991dfa 2 weeks ago 107MB
openjdk 8-jre-alpine e2f6fe2dacef 3 weeks ago 81.4MB
daocloud.io/library/tomcat 8.0.45-jre7 fa6ad595ba45 2 months ago 357MB
mytomcat 8.0 fa6ad595ba45 2 months ago 357MB
daocloud.io/daocloud/daocloud-toolset latest bbdc71e950ea 6 months ago 147MB