【问题标题】:docker - pull image and get it's id (linux cli)docker - 拉取图像并获取它的 id (linux cli)
【发布时间】:2018-07-05 10:28:35
【问题描述】:

我在 centos7 termnial 中运行这个命令:

 docker pull www.someRepository.com/authorization:latest

现在,我想运行“docker run”命令,但我需要知道创建的图像的 id

$id=commandThatParsesTheId

是否有从“docker images”列表中取回 id 的命令?

【问题讨论】:

    标签: linux docker centos7


    【解决方案1】:

    您可以使用图像的名称及其标签 或者你可以使用

    docker images -q | grep yourimagename

    docker images | grep yourimagename | awk {'print $3'}

    【讨论】:

    • 图片名称是什么?我在“docker images”命令中没有看到任何名称
    • docker run www.SomeRepository.com/authorization:latest - 与docker pulled 完全相同的名字
    【解决方案2】:

    您也许可以稍微清理一下,但以下应该可以工作:

        docker pull <someimage> | grep "Digest:" | cut -f2 -d " " > container_digest
        docker images --digests | grep $(cat container_digest) | sed -Ee 's/\s+/ /g' | cut -f4 -d " "
    

    它将您在拉取图像时收到的摘要映射到图像 ID。

    【讨论】:

      【解决方案3】:

      您也可以在图像名称上运行“docker run”命令而不是图像 ID

      docker pull www.someRepository.com/authorization:latest
      docker run -i -t www.someRepository.com/authorization:latest "/bin/bash"
      

      上面一个是运行容器的交互模式。

      你也可以获取镜像 id 来运行 docker run 命令

      docker images 
      docker run -i -t dockerid "/bin/bash"
      

      【讨论】:

        猜你喜欢
        • 2018-09-26
        • 2019-08-16
        • 1970-01-01
        • 2019-07-08
        • 1970-01-01
        • 2021-08-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-28
        相关资源
        最近更新 更多