Docker use local image with buildx
Asked Answered
F

1

19

I am building an image for a docker container running on a different architecture. 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. After I started to build the image with buildx, this does not seem to work anymore. Is there any way to tell docker to only use the local image? 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 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
Flexure answered 1/9, 2021 at 5:42 Comment(2)
did you find a solution to this? I'm also having this issue, where buildx build always tries to pull from the registry, but I want it to use a FROM image that I built locally (using buildx build --load)Lowelllowenstein
github.com/docker/buildx/issues/847Spongioblast
Z
1

My workaround for this is to explicitly state the registry in the Dockerfile FROM sections, be it your own private registry or dockerhub.

For example, to use the dockerhub ubuntu:latest image, instead of just doing FROM ubuntu:latest I would write in the Dockerfile:

FROM docker.io/library/ubuntu:latest

To use myprivateregistry:5000 I would use:

FROM myprivateregistry:5000/ubuntu:latest

And also you must set --pull=false flag for the docker buildx build or DOCKER_BUILDKIT=1 docker build commands. When you have internet again you can use --pull=true again

Zibeline answered 19/11, 2022 at 19:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.