Docker上手命令(一)

108 阅读2分钟

帮助命令

  • docker version
  • docker info
  • docker help
    这个docker help是不是很像其它的帮助命令 java help ,mvn help,下文中使用到镜像命令也可以用类似的帮助命令查询。

镜像命令

docker images 查看当前镜像

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/redis     latest              7614ae9453d1        2 years ago         113 MB

本地当前只有一个redis的镜像。镜像列出来,看下镜像每个列对应的信息。

REPOSITORYTAGIMAGE IDCREATEDSIZE
镜像仓库源镜像标签镜像ID创建时间大小

再看下docker images 的帮助命令,docker images --help

[root@localhost ~]# docker images --help

Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]

List images

Options:
  -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
      --help            Print usage
      --no-trunc        Don't truncate output
  -q, --quiet           Only show numeric IDs

重点看下参数 -a、-q。

-a-q
列出所有镜像只显示镜像ID
[root@localhost ~]# docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/redis     latest              7614ae9453d1        2 years ago         113 MB
[root@localhost ~]# docker images -q
7614ae9453d1

docker search 查找镜像

[root@localhost ~]# docker search jdk
INDEX       NAME                                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/java                                  DEPRECATED; use "openjdk" (or other JDK im...   1998      [OK]       
docker.io   docker.io/bellsoft/liberica-runtime-container   Alpaquita based image for Liberica JDK and...   17                   
docker.io   docker.io/eclipse/ubuntu_jdk8                   Ubuntu, JDK8, Maven 3, git, curl, nmap, mc...   15                   [OK]
docker.io   docker.io/jdkato/vale                           The official Docker image for Vale.             7                    
docker.io   docker.io/dockette/jdk8                         My Oracle Java 8 Dockerfile                     5                    [OK]

查找jdk镜像,可以找到很多jdk相关的镜像,看下对应的列什么意思。

NAMEDESCRIPTIONSTARSOFFICIALAUTOMATED
镜像仓库镜像描述信息镜像收藏数是否官方发布镜像是否自动化构建镜像

再看下docker search --help命令,看下相关的信息。

[root@localhost ~]# docker search --help

Usage:  docker search [OPTIONS] TERM

Search the Docker Hub for images

Options:
 -f, --filter filter   Filter output based on conditions provided
     --help            Print usage
     --limit int       Max number of search results (default 25)
     --no-index        Don't truncate output
     --no-trunc        Don't truncate output

通过帮助命令可以看到可选的搜索过滤命令。

[root@localhost ~]# docker search jdk --limit 4
INDEX       NAME                                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/java                                  DEPRECATED; use "openjdk" (or other JDK im...   1998      [OK]       
docker.io   docker.io/bellsoft/liberica-runtime-container   Alpaquita based image for Liberica JDK and...   17                   
docker.io   docker.io/eclipse/ubuntu_jdk8                   Ubuntu, JDK8, Maven 3, git, curl, nmap, mc...   15                   [OK]
docker.io   docker.io/dockette/jdk8                         My Oracle Java 8 Dockerfile                     5                    [OK]

docker search xx --limit 4安装搜索的结果条数过滤。

[root@localhost ~]# docker search jdk --filter=stars=10
INDEX       NAME                                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/java                                  DEPRECATED; use "openjdk" (or other JDK im...   1998      [OK]       
docker.io   docker.io/bellsoft/liberica-runtime-container   Alpaquita based image for Liberica JDK and...   17                   
docker.io   docker.io/eclipse/ubuntu_jdk8                   Ubuntu, JDK8, Maven 3, git, curl, nmap, mc...   15                   [OK]
[root@localhost ~]# 

docker search xx --filter=stars=10 搜索出的镜像的stars大于10

[root@localhost ~]# docker search jdk --filter=stars=10 --limit 15
INDEX       NAME                                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/java                                  DEPRECATED; use "openjdk" (or other JDK im...   1998      [OK]       
docker.io   docker.io/bellsoft/liberica-runtime-container   Alpaquita based image for Liberica JDK and...   17                   
docker.io   docker.io/eclipse/ubuntu_jdk8                   Ubuntu, JDK8, Maven 3, git, curl, nmap, mc...   15                   [OK]

也可以俩个结合。

docker 这些命令都带有help命令,我们可以通过这个help命令去学习、使用、并记住。