简体   繁体   English

Docker 使用带有 buildx 的本地镜像

[英]Docker use local image with buildx

I am building an image for a docker container running on a different architecture.我正在为在不同架构上运行的 docker 容器构建映像。 As I don't have internet access all the time, I usually just pull the image when I have internet and docker uses the local image instead of pulling a new one.由于我无法一直访问互联网,因此我通常只在有互联网的情况下拉取映像,而 docker 使用本地映像而不是拉取新映像。 After I started to build the image with buildx, this does not seem to work anymore.在我开始使用 buildx 构建映像后,这似乎不再起作用了。 Is there any way to tell docker to only use the local image?有什么办法可以告诉 docker 只使用本地镜像吗? When I have connection, docker seems to check wherever there is a new version available but uses the local (or cached) image as I would expect it without internet connection.当我有连接时,docker 似乎会检查任何有新版本可用的地方,但使用本地(或缓存)图像,正如我在没有互联网连接的情况下所期望的那样。

$ docker image ls
ros                     galactic          bac817d14f26   5 weeks ago    626MB
$ docker image inspect ros:galactic
...
"Architecture": "arm64",
 "Variant": "v8",
 "Os": "linux",
...

Example build command示例构建命令

$ 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

Below is a simple test.下面是一个简单的测试。 Images in buildx are not visible in docker. buildx 中的图像在 docker 中不可见。 Images are managed separately (as a cache layer).图像单独管理(作为缓存层)。

Dockerfile: 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker Buildx 无法从本地提取继承图像 - Docker Buildx Cannot Pull From Local for Inherited Image 如何使用 docker buildx 推送镜像到注册表使用 http 协议? - how to use docker buildx pushing image to registry use http protocol? Docker BuildX 图像未在 docker 图像 ls 中显示 - Docker BuildX image not showing in docker image ls 我如何将 docker buildx 构建到本地“注册表”容器中 - How do I docker buildx build into a local "registry" container 如何使用 docker buildx bake 替换 docker-compose up? - How to use docker buildx bake to replace docker-compose up? 将 docker buildx 功能与 Jenkins docker.build 一起使用 - Use docker buildx feature with Jenkins docker.build 在 Azure DevOps 管道中使用 docker/buildx 构建多体系结构映像 - Build multi architecture image using docker/buildx in Azure DevOps pipeline 使用 docker buildx 无法将图像推送到 resgistry:没有这样的主机 - using docker buildx failed to push image to resgistry: no such host GitLab CI - 尝试使用 docker buildx 为 ARM64 构建 - GitLab CI - Trying to use docker buildx to build for ARM64 docker buildx - 如何使用不同的 Dockerfile 或合二为一 - docker buildx - how to use different Dockerfile or switch in one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM