Okteto build was failed when I using multi-stage build

Building the following Dockerfile with okteto build fails.

Dockerfile

# syntax=docker/dockerfile:1
FROM rust:1.69 as builder
WORKDIR /app
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
    --mount=type=cache,target=/app/target \
    touch /app/src/main.rs && cargo build --release && mv target/release/tabi_plan /tabi_plan

FROM gcr.io/distroless/cc:latest
COPY --from=builder /tabi_plan /tabi_plan
ENTRYPOINT ["/tabi_plan"]

error message.

$ okteto build --platform=linux/amd64 -t okteto.dev/tabi_plan:latest -f infra/Dockerfile
 i  Building 'infra/Dockerfile' in tcp://buildkit.cloud.okteto.net:443...
[+] Building 18.4s (14/14) FINISHED
 => [internal] load .dockerignore                                                        0.5s
 => => transferring context: 131B                                                        0.5s
 => [internal] load build definition from buildkit-2441940337                            0.5s
 => => transferring dockerfile: 639B                                                     0.5s
 => resolve image config for docker.io/docker/dockerfile:1                               0.5s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372  0.0s
 => => resolve docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372a0817649ecb  0.0s
 => [internal] load metadata for gcr.io/distroless/cc:latest                             0.1s
 => [internal] load metadata for docker.io/library/rust:1.69                             0.4s
 => [builder 1/4] FROM docker.io/library/rust:1.69@sha256:ee5de9877e3df1180a2a95193ea95  0.0s
 => => resolve docker.io/library/rust:1.69@sha256:ee5de9877e3df1180a2a95193ea954afcaac9  0.0s
 => [stage-1 1/2] FROM gcr.io/distroless/cc:latest@sha256:9b8e0854865dcaf49470b4ec305df  0.0s
 => => resolve gcr.io/distroless/cc:latest@sha256:9b8e0854865dcaf49470b4ec305df45957020  0.0s
 => [internal] load build context                                                        0.8s
 => => transferring context: 36.68kB                                                     0.7s
 => CACHED [builder 2/4] WORKDIR /app                                                    0.0s
 => CACHED [builder 3/4] COPY . .                                                        0.0s
 => [builder 4/4] RUN --mount=type=cache,target=/usr/local/cargo/registry     --mount=  12.5s
 => CACHED [stage-1 2/2] COPY --from=builder /tabi_plan /tabi_plan                       0.0s
 => ERROR exporting to image                                                             0.6s
 => => exporting layers                                                                  0.0s
 => => exporting manifest sha256:79943eb90dd9d57b3dfd1a7aff8e162fdd0a40189291a646c7e335  0.0s
 => => exporting config sha256:85db76bde28f404462b587d8b08ab88e77c7eb8b205b625018c13c14  0.0s
 => => pushing layers                                                                    0.6s
------
 > exporting to image:
------
 x  Error building image 'registry.cloud.okteto.net/skanehira/tabi_plan:latest': build failed: failed to solve: content digest sha256:80ec95682aee84c463cbf19b82eef5e1707c5e31b7be9750e1a90bff8b4183ee: not found

But with Dcoker CLI it works.

I found out that okteto uses okteto build service by looking at Okteto CLI | Okteto Documentation
It’s seems like I can specify my own build service in BUILDKIT_HOST.
So I tried the following moby/buildkit:latest, but the result was failure.
It looked like BUILDKIT_HOST was not working.

$ okteto build --platform=linux/amd64 -t okteto.dev/tabi_plan:latest -f infra/Dockerfile .
 i  Building 'infra/Dockerfile' in tcp://buildkit.cloud.okteto.net:443...
[+] Building 4.2s (14/14) FINISHED
 => [internal] load build definition from buildkit-2347265822                                                                                                                           0.5s
 => => transferring dockerfile: 639B                                                                                                                                                    0.5s
 => [internal] load .dockerignore                                                                                                                                                       0.5s
 => => transferring context: 131B                                                                                                                                                       0.5s
 => resolve image config for docker.io/docker/dockerfile:1                                                                                                                              1.1s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372a0817649ecb2724562a38360f4d6a7782a409b14                                                         0.0s
 => => resolve docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372a0817649ecb2724562a38360f4d6a7782a409b14                                                                    0.0s
 => [internal] load metadata for gcr.io/distroless/cc:latest                                                                                                                            0.3s
 => [internal] load metadata for docker.io/library/rust:1.69                                                                                                                            0.8s
 => [builder 1/4] FROM docker.io/library/rust:1.69@sha256:ee5de9877e3df1180a2a95193ea954afcaac9c23d5dc3404cb987be5f2e432f8                                                              0.0s
 => => resolve docker.io/library/rust:1.69@sha256:ee5de9877e3df1180a2a95193ea954afcaac9c23d5dc3404cb987be5f2e432f8                                                                      0.0s
 => [internal] load build context                                                                                                                                                       0.7s
 => => transferring context: 36.68kB                                                                                                                                                    0.6s
 => [stage-1 1/2] FROM gcr.io/distroless/cc:latest@sha256:9b8e0854865dcaf49470b4ec305df45957020fbcf17b71eeb50ffd3bc5bf885d                                                              0.0s
 => => resolve gcr.io/distroless/cc:latest@sha256:9b8e0854865dcaf49470b4ec305df45957020fbcf17b71eeb50ffd3bc5bf885d                                                                      0.0s
 => CACHED [builder 2/4] WORKDIR /app                                                                                                                                                   0.0s
 => CACHED [builder 3/4] COPY . .                                                                                                                                                       0.0s
 => CACHED [builder 4/4] RUN --mount=type=cache,target=/usr/local/cargo/registry     --mount=type=cache,target=/app/target     touch /app/src/main.rs && cargo build --release && mv t  0.0s
 => CACHED [stage-1 2/2] COPY --from=builder /tabi_plan /tabi_plan                                                                                                                      0.0s
 => ERROR exporting to image                                                                                                                                                            0.6s
 => => exporting layers                                                                                                                                                                 0.0s
 => => exporting manifest sha256:79943eb90dd9d57b3dfd1a7aff8e162fdd0a40189291a646c7e3351c12e62c55                                                                                       0.0s
 => => exporting config sha256:85db76bde28f404462b587d8b08ab88e77c7eb8b205b625018c13c145ad74460                                                                                         0.0s
 => => pushing layers                                                                                                                                                                   0.6s
------
 > exporting to image:
------
 x  Error building image 'registry.cloud.okteto.net/skanehira/tabi_plan:latest': build failed: failed to solve: content digest sha256:1e3d9b7d145208fa8fa3ee1c9612d0adaac7255f1bbc9ddea7e461e0b317805c: not found

Does okteto cli support multi-stage builds?

Hi!

Yes, we do support multistage builds. Could you share your Dockerfile with us to see if something pops up there?

I tried again with no changes and succeeded :slight_smile:
I have no idea what caused it, but it seems to be OK for the time being :rofl:

$ make image-build
okteto build --platform=linux/amd64 -t okteto.dev/tabiplan:latest -f infra/Dockerfile
 i  Building 'infra/Dockerfile' in tcp://buildkit.cloud.okteto.net:443...
[+] Building 42.1s (11/13)
[+] Building 177.5s (14/14) FINISHED
 => [internal] load build definition from buildkit-4117823002                            0.6s
 => => transferring dockerfile: 639B                                                     0.5s
 => [internal] load .dockerignore                                                        0.6s
 => => transferring context: 131B                                                        0.5s
 => resolve image config for docker.io/docker/dockerfile:1                               0.6s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372  0.0s
 => => resolve docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372a0817649ecb  0.0s
 => [internal] load metadata for gcr.io/distroless/cc:latest                             0.1s
 => [internal] load metadata for docker.io/library/rust:1.69                             0.4s
 => [builder 1/4] FROM docker.io/library/rust:1.69@sha256:ee5de9877e3df1180a2a95193ea95  0.0s
 => => resolve docker.io/library/rust:1.69@sha256:ee5de9877e3df1180a2a95193ea954afcaac9  0.0s
 => CACHED [stage-1 1/2] FROM gcr.io/distroless/cc:latest@sha256:9b8e0854865dcaf49470b4  0.0s
 => => resolve gcr.io/distroless/cc:latest@sha256:9b8e0854865dcaf49470b4ec305df45957020  0.0s
 => [internal] load build context                                                        0.8s
 => => transferring context: 36.68kB                                                     0.7s
 => CACHED [builder 2/4] WORKDIR /app                                                    0.0s
 => [builder 3/4] COPY . .                                                               0.1s
 => [builder 4/4] RUN --mount=type=cache,target=/usr/local/cargo/registry     --mount  166.6s
 => [stage-1 2/2] COPY --from=builder /tabi_plan /tabi_plan                              0.2s
 => exporting to image                                                                   5.2s
 => => exporting layers                                                                  0.2s
 => => exporting manifest sha256:cb9ea8e15d51522fe2c1e896245b5147b3ea7693757a6fc3dd7804  0.0s
 => => exporting config sha256:f9ba40cfdf847fcf7e81ccb21859efd711a73f372c4c35512ef3935f  0.0s
 => => pushing layers                                                                    3.7s
 => => pushing manifest for registry.cloud.okteto.net/skanehira/tabiplan:latest@sha256:  1.3s
 ✓  Image 'registry.cloud.okteto.net/skanehira/tabiplan:latest' successfully pushed