docker / buildx

Docker CLI plugin for extended build capabilities with BuildKit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker Buildx Does Not Seem To Respect Output Type Flag

justinba1010 opened this issue · comments

Discussed in #2458

Originally posted by justinba1010 May 14, 2024
It seems that the output type flag is ignored during exports. Not sure if I am using this incorrectly. It seems to be documented here:
https://docs.docker.com/build/exporters/oci-docker/

Goal: To build a tarball that has the docker layout instead of OCI, in v24 and below this was default OCI Compliance PR

Steps to recreate:

  1. Compile a dockerfile build (used the hello world example)
➜  hello-world git:(master) ✗ docker buildx build --output type=docker -t hello .
  1. Save a tarball of image
➜  hello-world git:(master) ✗ docker save hello:latest -o out.tar

It would be expected that this tarball would have a docker image layout but it seems to be exported as an OCI image.

➜  hello-world git:(master) ✗ tar -tvf out.tar | grep oci
-rw-r--r-- 0/0              31 1969-12-31 19:00 oci-layout

There seems to be documentation for other methods to skip the save step, but I have been unable to get those to work as well.

➜  hello-world git:(master) ✗ docker buildx build --output "type=docker,tar=true,dest=out.tar" -t hello .
[+] Building 0.0s (0/0)                                                                    docker:default
ERROR: Docker exporter is not supported for the docker driver.
Switch to a different driver, or turn on the containerd image store, and try again.
Learn more at https://docs.docker.com/go/build-exporters/
➜  hello-world git:(master) ✗ docker buildx build --output "type=docker,tar=true" -t hello . 
➜  hello-world git:(master) ✗ docker version
Client: Docker Engine - Community
 Version:           26.1.2
 API version:       1.45
 Go version:        go1.21.10
 Git commit:        211e74b
 Built:             Wed May  8 13:59:59 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.1.2
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.10
  Git commit:       ef1912d
  Built:            Wed May  8 13:59:59 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.31
  GitCommit:        e377cd56a71523140ca6ae87e30244719194a521
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0```</div>

Save a tarball of image

If you are using docker save then it is this command that makes the tarball, not the builder.

Docker tar layout can be made compatible with OCI tar. Exporting Docker tarball does not mean that there can not be oci-layout file, but means that this tarball can be imported to (older) Docker engine. The file that defines this importing logic is in manifest.json that is not part of OCI spec.

ERROR: Docker exporter is not supported for the docker driver.

In order to export OCI tarball or Docker-compatible tarball directly from builder you need to use container/k8s/remote builder instance https://docs.docker.com/reference/cli/docker/buildx/create/ or containerd storage in your docker installation https://docs.docker.com/desktop/containerd/

If you want to control if the objects in the image use OCI or Docker mediatypes then the option for that is oci-mediatypes=true|false