networks (compose): Defines custom networks and which services join them. Services on the same network reach each other by service name. In Docker Compose, networks defines custom networks and which services join them. Services on the same network can reach each other by service name; services on different networks cannot. By default, Compose puts all services of a project on one network, which is enough for most setups. Custom networks are useful when you want separation, such as a front-end network for the web server and a back-end network for the database, so the web server can reach the app and the app can reach the database, but the web server cannot reach the database directly.
Frequently asked questions about networks (compose)
What should you keep in mind with networks (compose)?
Networks marked external let several Compose projects share one network, for example a reverse proxy that serves multiple applications. Keep the setup simple, though; more networks mean more to understand when something cannot connect.
What does an example of networks (compose) look like?
Use this skill when setting up, initializing, or Dockerizing a project, even if the user doesn't explicitly mention Docker but describes a need for containerized local development, adding a database or cache dependency, or running services without host-level installs. Covers Dockerfile, compose.yaml, and .dockerignore creation with Docker best practices.
Use this skill when creating, modifying, or debugging Docker Compose configurations, even if the user just says they need to wire services together, add a database to their stack, or set up a local development environment with multiple containers. Covers service definitions, health checks, dependency ordering, volumes, networks, environment variables, and development overrides.
Use this skill when writing, reviewing, or optimizing Dockerfiles, even if the user just says their image is too large, their build is slow, or they need to harden a container for production. Covers multi-stage builds, layer caching, .dockerignore, non-root users, and image size optimization.