Failed to create network project_default: Error response from daemon: all predefined address pools have been fully subnetted

├── external
│   └── Dockerfile
└── project
    ├── compose.yml
    └── Dockerfile

Let’s examine the contents of the files

+ cat external/Dockerfile
FROM scratch AS external

COPY <<EOF /test/external-hello
Hello!!!
EOF



+ cat project/compose.yml
services:
  hello:
    build:
      context: .
      additional_contexts:
        external: ../external
    command: cat /test/hello



+ cat project/Dockerfile
FROM scatch
COPY --from=external /test/external-hello /test/hello

Let’s do some tests

+ docker compose -f project/compose.yml run --rm hello
[+] Creating 1/0
 ✘ Network project_default  Error                                                                                 0.0s 
failed to create network project_default: Error response from daemon: all predefined address pools have been fully subnetted

Why?

Nothing to do with Dockerfiles. You probably run too many compose projects and there are no available ipranges left for your new projects. Delete the old networks.

+ docker network prune
WARNING! This will remove all custom networks not used by at least one container.
Are you sure you want to continue? [y/N] y


+ docker compose -f project/compose.yml run --rm hello
[+] Creating 1/1
 ✔ Network project_default  Created                                                                               0.1s 
[+] Building 0.1s (5/5) FINISHED                                                                        docker:default
 => [hello internal] load build definition from Dockerfile                                                        0.0s
 => => transferring dockerfile: 104B                                                                              0.0s
 => [hello context external] load .dockerignore                                                                   0.0s
 => => transferring external: 2B                                                                                  0.0s
 => [hello internal] load .dockerignore                                                                           0.0s
 => => transferring context: 2B                                                                                   0.0s
 => [hello context external] load from client                                                                     0.0s
 => => transferring external: 2B                                                                                  0.0s
 => ERROR [hello stage-0 1/1] COPY --from=external /test/external-hello /test/hello                               0.0s
------
 > [hello stage-0 1/1] COPY --from=external /test/external-hello /test/hello:
------
failed to solve: failed to compute cache key: failed to calculate checksum of ref 2f3be2ff-461b-400a-9dc7-67650870d8fb::oqy8sq0jiuj15v75fsw7up18j: "/test/external-hello": not found

So what is the purpose of what is written here docker - Can a Dockerfile extend another one? - Stack Overflow ?

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

Since there was no final answer, could we reopen or reply to the discussion?

I reopened this topic without thinking about the actual question, but I really can’t follow your logic. You had a docker network issue while asking about a Dockerfile and now you asked for reopening the topic because you got no answer to a post that just confuses people even more. You quoted my statement about your issue not being related to Dockerfile because it wasn’t, and referred to a stack overflow post about “additional contexts”, which was at least related to your actual issue but you said nothing about realizing that you shared the wrong error message for example. I really have no time to trying to figure out every topic, so in those cases you can assume you will either not get a reply or will get it much later.

Regarding additional contexts, your error message is still clear. The file cannot be found. The stackoverflow post shared the documentation to the additional_contexts option and the way you used it, it is for referring to another folder, but you use it as if you could refer to an image which was not even built. You only have the Dockerfile. So you could only copy the Dockerfile, but even then, you wouldn’t have a “test” subfolder. The external context is the external folder.

I think the topic you opened to ask for reopening this was referring to “Multi-stage”, but if you want that, you can find that by searching for multi-stage

What you are doing is not that. By the way, the cat command wouldn’t work either since you built the image from scratch, so there is no cat or anyhing else in that image.

I read the documentation more thoroughly, and learned a few more things.

As a result, I figured out what was wrong

In the place of

        external: ../external

I should have put something similar to

        external: service:XXX

or else

        external: docker-image://XXX

(not tested)

Anyway, to consolidate my new knowledge, I did a couple of experiments

+ tree
├── external
│   ├── context-file
│   └── Dockerfile
└── project
    ├── compose.yml
    └── Dockerfile



+ cat external/context-file
CONTEXT FILE CONTENT



+ cat external/Dockerfile
FROM scratch AS external

COPY <<EOF image-file
IMAGE FILE CONTENT
EOF



+ cat project/compose.yml
services:
  external:
    build: ../external
  test:
    build:
      context: .
      additional_contexts:
        # HELP/EXAMPLE resources: /path/to/resources
        # HELP/EXAMPLE app: docker-image://my-app:latest
        # HELP/EXAMPLE base: service:base # refer to an image built by another service
        # HELP/EXAMPLE source: https://github.com/myuser/project.git
        external-context: ../external
        external-image: service:external



+ cat project/Dockerfile
FROM bash

# HELP --from=<image|stage|context>
COPY --from=external-image image-file /external/
COPY --from=external-context context-file /external/



+ docker compose -f project/compose.yml run --rm test cat /external/context-file
CONTEXT FILE CONTENT



+ docker compose -f project/compose.yml run --rm test cat /external/image-file
IMAGE FILE CONTENT

Very good.

Now I can apply what I have learned, to the project I am working on (but that’s another story).