docker buildx在镜像列表中无法显示结果。

15
以下命令不会显示输出ubuntu1镜像:
docker buildx build -f 1.dockerfile -t ubuntu1 .
docker image ls | grep ubuntu1
# no output

1.dockerfile:

FROM ubuntu:latest
RUN echo "my ubuntu"

此外,我无法在其他Docker文件的FROM语句中使用该图像(两个构建都在我的本地Windows框上)。

2.dockerfile:

FROM ubuntu1
RUN echo "my ubuntu 2"

docker buildx build -f 2.dockerfile -t ubuntu2 .

#error:
WARNING: No output specified for docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
[+] Building 1.8s (4/4) FINISHED
 => [internal] load build definition from 2.dockerfile                                                                                                                                                        0.0s
 => => transferring dockerfile: 84B                                                                                                                                                                           0.0s
 => [internal] load .dockerignore                                                                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                                                               0.0s
 => ERROR [internal] load metadata for docker.io/library/ubuntu1:latest                                                                                                                                       1.8s
 => [auth] library/ubuntu1:pull token for registry-1.docker.io                                                                                                                                                0.0s
------
 > [internal] load metadata for docker.io/library/ubuntu1:latest:
------
2.dockerfile:1
--------------------
   1 | >>> FROM ubuntu1:latest
   2 |     RUN echo "my ubuntu 2"
   3 |
--------------------
error: failed to solve: ubuntu1:latest: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed (did you mean ubuntu:latest?)

有什么想法吗?我怎样能够看到buildx准备的内容并在另一个dockerfile中引用一个镜像?


你使用了2.dockerfile,但命令使用了1.dockerfile,docker buildx build -f 1.dockerfile -t ubuntu1 . - life888888
docker buildx build -f 1.dockerfile -t ubuntu1 . 是可以的,我在我的电脑上测试过了,没问题。我的环境是:Ubuntu 20.04,$ docker version 客户端: Docker Engine - Community 版本: 20.10.21 API 版本: 1.41 Go 版本: go1.18.7 Git 提交: baeda1f 构建时间: Tue Oct 25 18:02:21 2022 操作系统/架构: linux/amd64 上下文: 默认 实验性的: true - life888888
这当然是一个打字错误,我已经更新了构建2.dockerfile的命令。 - Sagi Mann
2
请参考此评论。您需要使用--load标志,加载构建的每个镜像,以便它们出现在docker images命令返回的列表中。 - devatherock
1个回答

20

好的,我找到了一个部分解决方案,根据文档,我需要添加--output type=docker。这将把docker放入镜像列表中。但是我仍然无法在第二个docker中使用它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接