Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to buid image using base image on local repo #301

Closed
ishii1648 opened this issue Jun 1, 2020 · 11 comments
Closed

how to buid image using base image on local repo #301

ishii1648 opened this issue Jun 1, 2020 · 11 comments

Comments

@ishii1648
Copy link

I want to build image for another cpu architecture (build image for arm64 on x86 ).
When base image is hosted on dokcer.io, I success to build image.
But when base image is only hosted on local repository, I fail to build image.

Can I build image using base image on local repository?
If so, could you tell me how to build?

base image(ubuntu:18.04) is hosted on dokcer.io -> success

$ cat Dockerfile
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y curl
WORKDIR /src
COPY . .
$ docker buildx build --platform linux/arm/v7 -t test-buildx --load . 
[+] Building 117.9s (10/10) FINISHED                                                                                                
 => [internal] load build definition from Dockerfile                                                                           0.1s
 => => transferring dockerfile: 123B                                                                                           0.0s
 => [internal] load .dockerignore                                                                                              0.0s
 => => transferring context: 2B                                                                                                0.0s
 => [internal] load metadata for docker.io/library/ubuntu:18.04                                                                3.3s
 => CACHED [1/4] FROM docker.io/library/ubuntu:18.04@sha256:3235326357dfb65f1781dbc4df3b834546d8bf914e82cce58e6e6b676e23ce8f   0.0s
 => => resolve docker.io/library/ubuntu:18.04@sha256:3235326357dfb65f1781dbc4df3b834546d8bf914e82cce58e6e6b676e23ce8f          0.0s
 => [internal] load build context                                                                                              0.0s
 => => transferring context: 123B                                                                                              0.0s
 => [2/4] RUN apt-get update && apt-get install -y curl                                                                      106.1s
 => [3/4] WORKDIR /src                                                                                                         0.1s
 => [4/4] COPY . .                                                                                                             0.0s
 => exporting to oci image format                                                                                              5.8s 
 => => exporting layers                                                                                                        3.0s 
 => => exporting manifest sha256:5b17b05614a3bc56d041b2b9c20287809a4d991c7eb5aea5edd967fa6d606d44                              0.0s 
 => => exporting config sha256:43053f0e59e955c21680843e3f75da89ef2729901a6e4b0d6ddd8b2525543c08                                0.0s 
 => => sending tarball                                                                                                         2.7s
 => importing to docker 
$ docker images | grep test-build
test-buildx                   latest              43053f0e59e9        About a minute ago   82.1MB

base image(test-buildx) is only hosted on local repository -> fail

$ cat Dockerfile
FROM test-buildx:latest
RUN apt-get update && apt-get install -y curl
WORKDIR /src
COPY . .
$ docker buildx build --platform linux/arm/v7 -t test-buildx2 --load .                                     
[+] Building 6.7s (5/8)                                                                                                             
 => [internal] load build definition from Dockerfile                                                                           0.0s
 => => transferring dockerfile: 129B                                                                                           0.0s
 => [internal] load .dockerignore                                                                                              0.0s
 => => transferring context: 2B                                                                                                0.0s
 => ERROR [internal] load metadata for docker.io/library/test-buildx:latest                                                    3.4s
 => ERROR [1/4] FROM docker.io/library/test-buildx:latest                                                                      3.3s
 => => resolve docker.io/library/test-buildx:latest                                                                            3.3s
 => [internal] load build context                                                                                              0.0s
 => => transferring context: 129B                                                                                              0.0s
------
 > [internal] load metadata for docker.io/library/test-buildx:latest:
------
------
 > [1/4] FROM docker.io/library/test-buildx:latest:
------
failed to solve: rpc error: code = Unknown desc = failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
@tonistiigi
Copy link
Member

I don't know what you mean by local repo. For registry on the localhost you need to put the builder container to host network with --driver-opt. For accessing images in docker images this is only possible with docker driver and not with container driver.

@manofthelionarmy
Copy link

manofthelionarmy commented Jun 22, 2020

I don't know what you mean by local repo. For registry on the localhost you need to put the builder container to host network with --driver-opt. For accessing images in docker images this is only possible with docker driver and not with container driver.

@tonistiigi Given that, then why does the documentation say this under ---driver? I used --load using docker-container driver just as the documentation said:
docker buildx build -f sample.Dockerfile -t <tag> . --platform linux/amd64,linux/arm64,linux/arm/v7 --load
From that I got an error:

------
 > exporting to oci image format:
------
failed to solve: rpc error: code = Unknown desc = docker exporter does not currently support exporting manifest lists

I believe I misunderstood what the documentation was telling me, and it is like you said from above. Please correct me if I'm wrong, I'm brand new to all of this and I'm learning.

@tonistiigi
Copy link
Member

@manofthelionarmy That seems unrelated. Current versions of Docker have no concept of a local multi-arch image, therefore there is no way to load them and load needs to happen single-arch at a time. Described in https://github.com/docker/buildx#docker . But this is unrelated to accessing images as base image.

@Shaked
Copy link

Shaked commented Jul 19, 2020

Hey @ishii1648 did you figure it out?

I am experiencing the same problem.

@jjlin
Copy link

jjlin commented Jan 6, 2021

The docker-container driver you need to use for multi-platform builds doesn't support accessing local images, so you need to pull from a registry, whether local or remote. You can run with a local registry by doing something like

# Run a local registry (https://hub.docker.com/_/registry) at localhost:5000.
$ docker run -d --name registry --network=host registry:2

# Push your image(s) to the local registry.
$ docker tag ubuntu:18.04 localhost:5000/ubuntu:18.04
$ docker push localhost:5000/ubuntu:18.04

# Create a `docker-container` builder with host networking.
$ docker buildx create --name builder --use --driver-opt network=host

# Build the image.
docker buildx build \
       --network=host \
       --build-arg LOCAL_REGISTRY="localhost:5000" \
       --platform linux/amd64,linux/arm64 \
       ...

with a Dockerfile like

ARG LOCAL_REGISTRY
FROM ${LOCAL_REGISTRY}/ubuntu:18.04
...

@re6exp
Copy link

re6exp commented Nov 26, 2021

I have the same problem. All is working, but no image is created in the local system.
Maybe we use this tool in the wrong way, do we?

@ndepal
Copy link

ndepal commented Dec 10, 2021

I'm running into the same issue. I understand the explanation, but I find the docker buildx build documentation quite confusing. Why is there the following option, if it always happens anyway and it is not possible to do anything else?

--pull  Always attempt to pull a newer version of the image

@tonistiigi
Copy link
Member

If you don't specify --pull on docker driver (or buildkit with containerd worker) then local docker or containerd image will be used without pulling anything from the registry.

I'm closing this one as the initial question has been answered and other comments look unrelated to it. If something was left unanswered open a new issue.

mflis added a commit to mflis/spinnaker-operator that referenced this issue Aug 16, 2022
- docker buildx doesn't allow to easily separate build and push step
so `make docker-package` and `make docker-push` needed to be merged
into one command

- Using locally built image in FROM directive seems impossible
with `docker buildx`, so all dockerfiles were merged into one.
See: docker/buildx#301 (comment)

- AWS_AIM_AUTHENTICATOR_VERSION and GOOGLE_CLOUD_SDK_VERSION were bumped
  to versions where arm64 binaries are available
mflis added a commit to mflis/spinnaker-operator that referenced this issue Aug 16, 2022
- docker buildx doesn't allow to easily separate build and push step
so `make docker-package` and `make docker-push` needed to be merged
into one command

- Using locally built image in FROM directive seems impossible
with `docker buildx` - remote docker registry is required.
So all dockerfiles were merged into one.
See: docker/buildx#301 (comment)

- AWS_AIM_AUTHENTICATOR_VERSION and GOOGLE_CLOUD_SDK_VERSION were bumped
  to versions where arm64 binaries are available
mflis added a commit to mflis/spinnaker-operator that referenced this issue Aug 16, 2022
- docker buildx doesn't allow to easily separate build and push step
so `make docker-package` and `make docker-push` needed to be merged
into one command

- Using locally built image in FROM directive seems impossible
with `docker buildx` - remote docker registry is required.
So all dockerfiles were merged into one.
See: docker/buildx#301 (comment)

- AWS_AIM_AUTHENTICATOR_VERSION and GOOGLE_CLOUD_SDK_VERSION were bumped
  to versions where arm64 binaries are available
mflis added a commit to mflis/spinnaker-operator that referenced this issue Aug 17, 2022
- docker buildx doesn't allow to easily separate build and push step
so `make docker-package` and `make docker-push` needed to be merged
into one command

- Using locally built image in FROM directive seems impossible
with `docker buildx` - remote docker registry is required.
So all dockerfiles were merged into one.
See: docker/buildx#301 (comment)

- AWS_AIM_AUTHENTICATOR_VERSION and GOOGLE_CLOUD_SDK_VERSION were bumped
  to versions where arm64 binaries are available
@crazy-max crazy-max added kind/docs and removed docs labels Sep 10, 2022
@agirault
Copy link

agirault commented Dec 1, 2022

I still don't think @ishii1648's original question was answered here, please correct if I'm wrong: when calling docker buildx build, they only passed a single platform to --platforms, and passed --load (export as docker image on the client). Now the question becomes:

  1. how to use that docker image on the client as a base image for a new single-arch buildx build
  2. if that's not possible from --load/--output=type=docker, can it be done with another client-side output type (local, tar, oci) without requiring a registry (even local, as suggested by @jjlin) ?

@gugau-fr
Copy link

gugau-fr commented Dec 6, 2022

Hello.

I agree with you @agirault , the question is not answered.

@tonistiigi I have the same need: being able to use an image built locally as base image using buildx.
Why ? Tons of reason: using a shared base image locally only (no need to push it), don't push before a complete build (all images), ...
Why I use buildx instead of usual build ? Because I need to build multi arch images.
We need to have the local docker tags available during buildx build as the usual build do.

Just because we don't have these tags, moving from usual mono arch build to buildx multi arch build is very complicated once the build is not following the "happy path".
I need to found a way to make my build works (with workarounds for now) within a reasonable amount of time and may consider using an other tool...

Having improvements implemented on this topic would really save a lot of time to a lot of people.

Thanks.

@agirault
Copy link

agirault commented Dec 6, 2022

I'm closing this one as the initial question has been answered and other comments look unrelated to it. If something was left unanswered open a new issue. - @tonistiigi

I opened #1453

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants