Skip to content
Latchkey

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:integration

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →