命令:docker image 镜像管理命令
Usage: docker image COMMAND
PS C:\Users\DELL> docker image --helpUsage: docker image COMMANDCommands:build Build an image from a Dockerfilehistory Show the history of an imageimport Import the contents from a tarball to create a filesystem imageinspect Display detailed information on one or more imagesload Load an image from a tar archive or STDINls List imagesprune Remove unused imagespull Pull an image or a repository from a registrypush Push an image or a repository to a registryrm Remove one or more imagessave Save one or more images to a tar archive (streamed to STDOUT by default)tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGERun 'docker image COMMAND --help' for more information on a command.
例子:管理命令举例
Usage: docker image ls [OPTIONS] [REPOSITORY[:TAG]]
PS C:\Users\DELL> docker image ls --helpUsage: docker image ls [OPTIONS] [REPOSITORY[:TAG]]List imagesAliases:ls, listOptions:-a, --all Show all images (default hides intermediate images)--digests Show digests-f, --filter filter Filter output based on conditions provided--format string Pretty-print images using a Go template--no-trunc Don't truncate output-q, --quiet Only show image IDsPS C:\Users\DELL> docker image ls -aREPOSITORY TAG IMAGE ID CREATED SIZEminio/minio latest f55b2545c435 2 days ago 191MBiredmail/mariadb stable e4899534d71b 3 weeks ago 761MBdocker/getting-started latest 3ba8f2ff0727 2 months ago 27.9MBlejmr/iredmail mysql-latest f719a06cbe14 9 months ago 861MBPS C:\Users\DELL>
命令使用
查看镜像列表 docker images
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
PS C:\Users\DELL> docker images --helpUsage: docker images [OPTIONS] [REPOSITORY[:TAG]]List imagesOptions:-a, --all Show all images (default hides intermediate images)--digests Show digests-f, --filter filter Filter output based on conditions provided--format string Pretty-print images using a Go template--no-trunc Don't truncate output-q, --quiet Only show image IDsPS C:\Users\DELL> docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEminio/minio latest f55b2545c435 2 days ago 191MBiredmail/mariadb stable e4899534d71b 3 weeks ago 761MBdocker/getting-started latest 3ba8f2ff0727 2 months ago 27.9MBlejmr/iredmail mysql-latest f719a06cbe14 9 months ago 861MBPS C:\Users\DELL>
拉取镜像 docker pull
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
PS C:\Users\DELL> docker pull --helpUsage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]Pull an image or a repository from a registryOptions:-a, --all-tags Download all tagged images in the repository--disable-content-trust Skip image verification (default true)--platform string Set platform if server is multi-platformcapable-q, --quiet Suppress verbose outputPS C:\Users\DELL> docker image pull --helpUsage: docker image pull [OPTIONS] NAME[:TAG|@DIGEST]Pull an image or a repository from a registryOptions:-a, --all-tags Download all tagged images in the repository--disable-content-trust Skip image verification (default true)--platform string Set platform if server is multi-platformcapable-q, --quiet Suppress verbose outputPS C:\Users\DELL>
例子 docker pull
PS C:\Users\DELL> docker pull httpdUsing default tag: latestlatest: Pulling from library/httpd69692152171a: Pull complete7284b4e0cc7b: Pull complete3678b2d55ccd: Pull completeab492cf0b2a4: Pull complete991f7f97a9d8: Pull completeDigest: sha256:e4c2b93c04762468a6cce6d507d94def02ef4dc285278d0d926e09827f4857dbStatus: Downloaded newer image for httpd:latestdocker.io/library/httpd:latestPS C:\Users\DELL>
查询镜像 docker search
Usage: docker search [OPTIONS] TERM
PS C:\Users\DELL> docker search --helpUsage: docker search [OPTIONS] TERMSearch the Docker Hub for imagesOptions:-f, --filter filter Filter output based on conditions provided--format string Pretty-print search using a Go template--limit int Max number of search results (default 25)--no-trunc Don't truncate outputPS C:\Users\DELL> docker search redisNAME DESCRIPTION STARS OFFICIAL AUTOMATEDredis Redis is an open source key-value store that… 9446 [OK]bitnami/redis Bitnami Redis Docker Image 180 [OK]sameersbn/redis 83 [OK]grokzen/redis-cluster Redis cluster 3.0, 3.2, 4.0, 5.0, 6.0, 6.2 78rediscommander/redis-commander Alpine image for redis-commander - Redis man… 58 [OK]redislabs/redisearch Redis With the RedisSearch module pre-loaded… 34redislabs/redisinsight RedisInsight - The GUI for Redis 30redislabs/redis Clustered in-memory database engine compatib… 30oliver006/redis_exporter Prometheus Exporter for Redis Metrics. Supp… 25redislabs/rejson RedisJSON - Enhanced JSON data type processi… 23arm32v7/redis Redis is an open source key-value store that… 23bitnami/redis-sentinel Bitnami Docker Image for Redis Sentinel 22 [OK]redislabs/redisgraph A graph database module for Redis 15 [OK]arm64v8/redis Redis is an open source key-value store that… 12redislabs/redismod An automated build of redismod - latest Redi… 12 [OK]webhippie/redis Docker images for Redis 11 [OK]insready/redis-stat Docker image for the real-time Redis monitor… 10 [OK]s7anley/redis-sentinel-docker Redis Sentinel 10 [OK]goodsmileduck/redis-cli redis-cli on alpine 9 [OK]circleci/redis CircleCI images for Redis 7 [OK]centos/redis-32-centos7 Redis in-memory data structure store, used a… 5clearlinux/redis Redis key-value data structure server with t… 3wodby/redis Redis container image with orchestration 1 [OK]tiredofit/redis Redis Server w/ Zabbix monitoring and S6 Ove… 1 [OK]xetamus/redis-resource forked redis-resource 0 [OK]PS C:\Users\DELL>
NAME: 镜像仓库源的名称
DESCRIPTION: 镜像的描述
OFFICIAL: 是否 docker 官方发布
stars: 类似 Github 里面的 star,表示点赞、喜欢的意思。
AUTOMATED: 自动构建。
删除镜像 docker rmi
Usage: docker rmi [OPTIONS] IMAGE [IMAGE…]
PS C:\Users\DELL> docker rmi --helpUsage: docker rmi [OPTIONS] IMAGE [IMAGE...]Remove one or more imagesOptions:-f, --force Force removal of the image--no-prune Do not delete untagged parentsPS C:\Users\DELL> docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEminio/minio latest f55b2545c435 2 days ago 191MBredis latest bc8d70f9ef6c 5 days ago 105MBhttpd latest f3cffeea581b 5 days ago 138MBiredmail/mariadb stable e4899534d71b 3 weeks ago 761MBdocker/getting-started latest 3ba8f2ff0727 2 months ago 27.9MBlejmr/iredmail mysql-latest f719a06cbe14 9 months ago 861MBPS C:\Users\DELL> docker rmi httpd:latestUntagged: httpd:latestUntagged: httpd@sha256:e4c2b93c04762468a6cce6d507d94def02ef4dc285278d0d926e09827f4857dbDeleted: sha256:f3cffeea581b3306a13d80b25a437f73f767b8f27afdb29393b3764b9dfaea69Deleted: sha256:887d0217b7251e4d5ad46486c19c5e2c82ae8aa6d53c3ffb729f032028a5f1c9Deleted: sha256:e04f6a8ae4f2939d3b73fd06085169c625486a81d3823fba3fdad029b2017347Deleted: sha256:85643304b5484a30ffe669196e71d6b763661800e12beb7ff131615040906adbDeleted: sha256:7524155083fa19d15b8902105916a8da484d1ff5d362d3530d871511c1f13f2aPS C:\Users\DELL>
更新 update、构建 build、提交 commit、发布 push 镜像
参考:https://www.runoob.com/docker/docker-image-usage.html
创建镜像当我们从 docker 镜像仓库中下载的镜像不能满足我们的需求时,我们可以通过以下两种方式对镜像进行更改。1、从已经创建的容器中更新镜像,并且提交这个镜像2、使用 Dockerfile 指令来创建一个新的镜像更新镜像更新镜像之前,我们需要使用镜像来创建一个容器。runoob@runoob:~$ docker run -t -i ubuntu:15.10 /bin/bashroot@e218edb10161:/#在运行的容器内使用 apt-get update 命令进行更新。在完成操作之后,输入 exit 命令来退出这个容器。此时 ID 为 e218edb10161 的容器,是按我们的需求更改的容器。我们可以通过命令 docker commit 来提交容器副本。runoob@runoob:~$ docker commit -m="has update" -a="runoob" e218edb10161 runoob/ubuntu:v2sha256:70bf1840fd7c0d2d8ef0a42a817eb29f854c1af8f7c59fc03ac7bdee9545aff8各个参数说明:-m: 提交的描述信息-a: 指定镜像作者e218edb10161:容器 IDrunoob/ubuntu:v2: 指定要创建的目标镜像名我们可以使用 docker images 命令来查看我们的新镜像 runoob/ubuntu:v2:runoob@runoob:~$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZErunoob/ubuntu v2 70bf1840fd7c 15 seconds ago 158.5 MBubuntu 14.04 90d5884b1ee0 5 days ago 188 MBphp 5.6 f40e9e0f10c8 9 days ago 444.8 MBnginx latest 6f8d099c3adc 12 days ago 182.7 MBmysql 5.6 f2e8d6c772c0 3 weeks ago 324.6 MBhttpd latest 02ef73cf1bc0 3 weeks ago 194.4 MBubuntu 15.10 4e3b13c8a266 4 weeks ago 136.3 MBhello-world latest 690ed74de00f 6 months ago 960 Btraining/webapp latest 6fae60ef3446 12 months ago 348.8 MB使用我们的新镜像 runoob/ubuntu 来启动一个容器runoob@runoob:~$ docker run -t -i runoob/ubuntu:v2 /bin/bashroot@1a9fbdeb5da3:/#构建镜像我们使用命令 docker build , 从零开始来创建一个新的镜像。为此,我们需要创建一个 Dockerfile 文件,其中包含一组指令来告诉 Docker 如何构建我们的镜像。runoob@runoob:~$ cat DockerfileFROM centos:6.7MAINTAINER Fisher "fisher@sudops.com"RUN /bin/echo 'root:123456' |chpasswdRUN useradd runoobRUN /bin/echo 'runoob:123456' |chpasswdRUN /bin/echo -e "LANG=\"en_US.UTF-8\"" >/etc/default/localEXPOSE 22EXPOSE 80CMD /usr/sbin/sshd -D每一个指令都会在镜像上创建一个新的层,每一个指令的前缀都必须是大写的。第一条FROM,指定使用哪个镜像源RUN 指令告诉docker 在镜像内执行命令,安装了什么。。。然后,我们使用 Dockerfile 文件,通过 docker build 命令来构建一个镜像。runoob@runoob:~$ docker build -t runoob/centos:6.7 .Sending build context to Docker daemon 17.92 kBStep 1 : FROM centos:6.7---> d95b5ca17cc3Step 2 : MAINTAINER Fisher "fisher@sudops.com"---> Using cache---> 0c92299c6f03Step 3 : RUN /bin/echo 'root:123456' |chpasswd---> Using cache---> 0397ce2fbd0aStep 4 : RUN useradd runoob......参数说明:-t :指定要创建的目标镜像名. :Dockerfile 文件所在目录,可以指定Dockerfile 的绝对路径使用docker images 查看创建的镜像已经在列表中存在,镜像ID为860c279d2fecrunoob@runoob:~$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZErunoob/centos 6.7 860c279d2fec About a minute ago 190.6 MBrunoob/ubuntu v2 70bf1840fd7c 17 hours ago 158.5 MBubuntu 14.04 90d5884b1ee0 6 days ago 188 MBphp 5.6 f40e9e0f10c8 10 days ago 444.8 MBnginx latest 6f8d099c3adc 12 days ago 182.7 MBmysql 5.6 f2e8d6c772c0 3 weeks ago 324.6 MBhttpd latest 02ef73cf1bc0 3 weeks ago 194.4 MBubuntu 15.10 4e3b13c8a266 5 weeks ago 136.3 MBhello-world latest 690ed74de00f 6 months ago 960 Bcentos 6.7 d95b5ca17cc3 6 months ago 190.6 MBtraining/webapp latest 6fae60ef3446 12 months ago 348.8 MB我们可以使用新的镜像来创建容器runoob@runoob:~$ docker run -t -i runoob/centos:6.7 /bin/bash[root@41c28d18b5fb /]# id runoobuid=500(runoob) gid=500(runoob) groups=500(runoob)从上面看到新镜像已经包含我们创建的用户 runoob。
设置镜像 tag
Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
PS C:\Users\DELL> docker tag --helpUsage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]Create a tag TARGET_IMAGE that refers to SOURCE_IMAGEPS C:\Users\DELL> docker tag httpd:latest httpd_1:latest_1PS C:\Users\DELL> docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEminio/minio latest f55b2545c435 2 days ago 191MBredis latest bc8d70f9ef6c 5 days ago 105MBhttpd latest f3cffeea581b 6 days ago 138MBhttpd_1 latest_1 f3cffeea581b 6 days ago 138MBiredmail/mariadb stable e4899534d71b 3 weeks ago 761MBdocker/getting-started latest 3ba8f2ff0727 2 months ago 27.9MBlejmr/iredmail mysql-latest f719a06cbe14 9 months ago 861MBPS C:\Users\DELL>
