---
title: Networks top-level elements
description: Explore all the attributes the networks top-level element can have.
keywords: compose, compose specification, networks, compose file reference
aliases:
- /compose/compose-file/06-networks/
weight: 30
---
{{% include "compose/networks.md" %}}
To use a network across multiple services, you must explicitly grant each service access by using the [networks](services.md) attribute within the `services` top-level element. The `networks` top-level element has additional syntax that provides more granular control.
## Examples
### Basic example
In the following example, at runtime, networks `front-tier` and `back-tier` are created and the `frontend` service
is connected to `front-tier` and `back-tier` networks.
```yml
services:
frontend:
image: example/webapp
networks:
- front-tier
- back-tier
networks:
front-tier:
back-tier:
```
### Advanced example
```yml
services:
proxy:
build: ./proxy
networks:
- frontend
app:
build: ./app
networks:
- frontend
- backend
db:
image: postgres
networks:
- backend
networks:
frontend:
# Specify driver options
driver: bridge
driver_opts:
com.docker.network.bridge.host_binding_ipv4: "127.0.0.1"
backend:
# Use a custom driver
driver: custom-driver
```
The advanced example shows a Compose file which defines two custom networks. The `proxy` service is isolated from the `db` service, because they do not share a network in common. Only `app` can talk to both.
## The default network
When a Compose file doesn't declare explicit networks, Compose uses an implicit `default` network. Services without an explicit [`networks`](services.md#networks) declaration are connected by Compose to this `default` network:
```yml
services:
some-service:
image: foo
```
This example is actually equivalent to:
```yml
services:
some-service:
image: foo
networks:
default: {}
networks:
default: {}
```
You can customize the `default` network with an explicit declaration:
```yml
networks:
default:
name: a_network # Use a custom name
driver_opts: # pass options to driver for network creation
com.docker.network.bridge.host_binding_ipv4: 127.0.0.1
```
For options, see the [Docker Engine docs](https://docs.docker.com/engine/network/drivers/bridge/#options).
## Attributes
### `driver`
`driver` specifies which driver should be used for this network. Compose returns an error if the
driver is not available on the platform.
```yml
networks:
db-data:
driver: bridge
```
For more information on drivers and available options, see [Network drivers](/manuals/engine/network/drivers/_index.md).
### `driver_opts`
`driver_opts` specifies a list of options as key-value pairs to pass to the driver. These options are
driver-dependent.
```yml
networks:
frontend:
driver: bridge
driver_opts:
com.docker.network.bridge.host_binding_ipv4: "127.0.0.1"
```
Consult the [network drivers documentation](/manuals/engine/network/_index.md) for more information.
### `attachable`
If `attachable` is set to `true`, then standalone containers should be able to attach to this network, in addition to services.
If a standalone container attaches to the network, it can communicate with services and other standalone containers
that are also attached to the network.
```yml
networks:
mynet1:
driver: overlay
attachable: true
```
### `enable_ipv4`
{{< summary-bar feature_name="Compose enable ipv4" >}}
`enable_ipv4` can be used to disable IPv4 address assignment.