gpt4 book ai didi

Docker 使用带有 buildx 的本地镜像

转载 作者:行者123 更新时间:2023-12-04 13:51:31 27 4
gpt4 key购买 nike

我正在为在不同架构上运行的 docker 容器构建镜像。由于我无法一直访问互联网,因此我通常只在有互联网的情况下拉取镜像,而 docker 使用本地镜像而不是拉取新镜像。在我开始使用 buildx 构建镜像后,这似乎不再起作用了。有什么办法可以告诉 docker 只使用本地镜像吗?当我有连接时,docker 似乎会检查任何有新版本可用的地方,但使用本地(或缓存)图像,正如我在没有互联网连接的情况下所期望的那样。

$ docker image ls
ros galactic bac817d14f26 5 weeks ago 626MB
$ docker image inspect ros:galactic
...
"Architecture": "arm64",
"Variant": "v8",
"Os": "linux",
...
示例构建命令
$ docker buildx build . --platform linux/arm64
WARN[0000] 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 0.3s (3/3) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 72B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> ERROR [internal] load metadata for docker.io/library/ros:galactic 0.0s
------
> [internal] load metadata for docker.io/library/ros:galactic:
------
Dockerfile:1
--------------------
1 | >>> FROM ros:galactic
2 | RUN "echo hello"
3 |
--------------------
error: failed to solve: failed to fetch anonymous token: Get "https://auth.docker.io/token?scope=repository%3Alibrary%2Fros%3Apull&service=registry.docker.io": proxyconnect tcp: dial tcp 127.0.0.1:3333: connect: connection refused

最佳答案

下面是一个简单的测试。
buildx 中的图像在 docker 中不可见。图像单独管理(作为缓存层)。
Dockerfile:

FROM alpine:3.14
RUN echo "HELLO WORLD"
$ docker image ls | grep alpine | grep "3\.14"
(EMPTY)

$ docker buildx build .
[+] Building 4.4s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 79B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/alpine:3.14 3.5s
=> [1/2] FROM docker.io/library/alpine:3.14@sha256:e1c082e3d3c45cccac829840a25941e679c25d438cc8412c2fa221cf1a824e6a 0.0s
=> => resolve docker.io/library/alpine:3.14@sha256:e1c082e3d3c45cccac829840a25941e679c25d438cc8412c2fa221cf1a824e6a 0.0s
=> => sha256:e1c082e3d3c45cccac829840a25941e679c25d438cc8412c2fa221cf1a824e6a 1.64kB / 1.64kB 0.0s
=> => sha256:69704ef328d05a9f806b6b8502915e6a0a4faa4d72018dc42343f511490daf8a 528B / 528B 0.0s
=> => sha256:14119a10abf4669e8cdbdff324a9f9605d99697215a0d21c360fe8dfa8471bab 1.47kB / 1.47kB 0.0s
=> [2/2] RUN echo "HELLO WORLD" 0.4s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:9c2f6f3712c2dc2c2e4684821eddea260a444b76c2017f197e30d0f4c4542bd9 0.0s



$ docker buildx build .
[+] Building 1.4s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 31B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/alpine:3.14 1.1s
=> [1/2] FROM docker.io/library/alpine:3.14@sha256:e1c082e3d3c45cccac829840a25941e679c25d438cc8412c2fa221cf1a824e6a 0.0s
=> CACHED [2/2] RUN echo "HELLO WORLD" 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:9c2f6f3712c2dc2c2e4684821eddea260a444b76c2017f197e30d0f4c4542bd9 0.0s

$ docker image ls | grep alpine | grep "3\.14"
(EMPTY)

关于Docker 使用带有 buildx 的本地镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69008316/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com