Error response from daemon: failed to set up container networking: network fix7-net not found — the container asks for a network that does not exist, or no longer exists. Create it with docker network create before the run; for a Compose project whose network was removed, recreate the containers with docker compose up -d --force-recreate.

docker run never creates a user-defined network for you. Compose creates its networks, but only in up. docker network ls shows what exists right now.

The error

PS> docker run --rm --network fix7-net alpine true
docker: Error response from daemon: failed to set up container networking: network fix7-net not found

Run 'docker run --help' for more information

The Compose variant names the lost network by its ID instead:

PS> docker compose start
 Container fix7-dep-db-1 Starting
Error response from daemon: failed to set up container networking: network c774d607bf74754988f5c4f4075393302d16054b288a452ffc0b9c69bd17895f not found

Why it happens

--network takes the name of a network that already exists. Docker looks it up when it sets up the container and stops if the lookup fails; there is no create-on-demand. Typical ways to get here are a typo, a setup script that creates the network not having run yet on this machine, and the short name of a Compose network: Compose puts the project name in front, so the network in this test was called fix7-dep_default.

The second way in is a network removed under a stopped container. docker network rm refused while the project ran, with has active endpoints, but once the containers had stopped it removed the network without complaint. The containers kept their reference and failed at the next start. docker compose start only starts existing containers and creates nothing. docker compose up -d did create a new fix7-dep_default, yet the old containers still pointed at the removed network's ID and failed again with the same message.

The fix

PS> docker network create fix7-net
95eeb8f9d9b44a53883a8d355c43ca22bf47f4b84bddb8cda34bc8f1b008fd14
PS> docker network ls --filter name=fix7-
NETWORK ID     NAME               DRIVER    SCOPE
c774d607bf74   fix7-dep_default   bridge    local
95eeb8f9d9b4   fix7-net           bridge    local
PS> docker run --rm --network fix7-net alpine sh -c "ip -4 -o addr show eth0"
2: eth0    inet 172.21.0.2/16 brd 172.21.255.255 scope global eth0\       valid_lft forever preferred_lft forever

For a plain container whose network was removed, creating the network again under the same name was enough here: docker start fix7-net-old then succeeded. For the Compose project, new containers were needed:

PS> docker compose up -d --force-recreate
 Container fix7-dep-db-1 Recreate
 Container fix7-dep-db-1 Recreated
 Container fix7-dep-web-1 Recreate
 Container fix7-dep-web-1 Recreated
 Container fix7-dep-db-1 Starting
 Container fix7-dep-db-1 Started
 Container fix7-dep-web-1 Starting
 Container fix7-dep-web-1 Started

docker compose down followed by docker compose up -d worked too, in a second run of the same test. The habit that avoids all of this: let Compose own its networks. up creates them and down removes them, so a project network never needs docker network rm by hand.

How it was reproduced

Docker Desktop 4.96.3 with engine 29.9.2 and Docker Compose v5.6.1, from Windows PowerShell 5.1, with the cached alpine:latest and postgres:16 images. The plain case ran docker run before the network existed, then removed the network under a created but stopped container. The Compose case used a two-service project, stopped it with docker compose stop and removed its default network. fix7-net, fix7-net-old and the project fix7-dep are the test's own names, all removed afterwards.

Frequently asked

How do I fix 'network not found' in docker run?
Create the network first with docker network create and the same name, and check the spelling with docker network ls. docker run does not create user-defined networks on demand.
Why does docker compose start say network not found?
The project's network was removed while its containers were stopped. compose start only starts existing containers. Run docker compose up -d --force-recreate, or docker compose down and then docker compose up -d.
Can I remove a Docker network that a stopped container uses?
Yes. docker network rm refused only while containers were running, with has active endpoints. Once they had stopped it removed the network, and the containers failed with network not found at their next start.

More decoded errors in the Fixes category. How container networks, published ports and container names fit together on Windows: Ports and networking: who binds what, where.