docker network create Command Reference
Create a user-defined network.
docker network create makes a user-defined network, usually a bridge, on which containers can resolve each other by name via Docker DNS. In CI it wires up a service container and a test container so the tests can reach the service by hostname.
Common flags
-d, --driver- network driver, e.g. bridge (default) or overlay--subnet- assign a custom subnet, e.g. 172.30.0.0/16--gateway- set the gateway for the subnet--internal- restrict external access from the network--attachable- allow standalone containers to attach (overlay)
Example
shell
docker network create ci-net
docker run -d --name db --network ci-net postgres:16
docker run --rm --network ci-net -e DB_HOST=db myorg/app npm run test:integrationIn CI
On a user-defined bridge, containers reach each other by container name (here, db) rather than by IP, which keeps test config stable across runs. The default bridge does not provide name resolution, so always create a network for multi-container tests. docker compose creates one automatically.
Key takeaways
- User-defined bridges give containers DNS resolution by name; the default bridge does not.
- Attach service and test containers to the same network with --network.
- docker compose provisions a project network for you automatically.
Related guides
docker run Command ReferenceReference for docker run in CI: --rm, -e, -v, --network, -w, and --entrypoint flags for creating and starting…
docker inspect Command ReferenceReference for docker inspect in CI: print low-level JSON for containers, images, volumes, and networks, and e…
docker compose up Command ReferenceReference for docker compose up in CI: start services from a compose file with -d, --build, and --wait so dep…