`mem_limit` configures a limit on the amount of memory a container can allocate, set as a string expressing a [byte value](extension.md#specifying-byte-values).
When set, `mem_limit` must be consistent with the `limits.memory` attribute in the [Deploy Specification](deploy.md#memory).
### `mem_reservation`
`mem_reservation` configures a reservation on the amount of memory a container can allocate, set as a string expressing a [byte value](extension.md#specifying-byte-values).
When set, `mem_reservation` must be consistent with the `reservations.memory` attribute in the [Deploy Specification](deploy.md#memory).
### `mem_swappiness`
`mem_swappiness` defines as a percentage, a value between 0 and 100, for the host kernel to swap out
anonymous memory pages used by a container.
- `0`: Turns off anonymous page swapping.
- `100`: Sets all anonymous pages as swappable.
The default value is platform specific.
### `memswap_limit`
`memswap_limit` defines the amount of memory the container is allowed to swap to disk. This is a modifier
attribute that only has meaning if [`memory`](deploy.md#memory) is also set. Using swap lets the container write excess
memory requirements to disk when the container has exhausted all the memory that is available to it.
There is a performance penalty for applications that swap memory to disk often.
- If `memswap_limit` is set to a positive integer, then both `memory` and `memswap_limit` must be set. `memswap_limit` represents the total amount of memory and swap that can be used, and `memory` controls the amount used by non-swap memory. So if `memory`="300m" and `memswap_limit`="1g", the container can use 300m of memory and 700m (1g - 300m) swap.
- If `memswap_limit` is set to 0, the setting is ignored, and the value is treated as unset.
- If `memswap_limit` is set to the same value as `memory`, and `memory` is set to a positive integer, the container does not have access to swap.
- If `memswap_limit` is unset, and `memory` is set, the container can use as much swap as the `memory` setting, if the host container has swap memory configured. For instance, if `memory`="300m" and `memswap_limit` is not set, the container can use 600m in total of memory and swap.
- If `memswap_limit` is explicitly set to -1, the container is allowed to use unlimited swap, up to the amount available on the host system.
### `network_mode`
`network_mode` sets a service container's network mode.
- `none`: Turns off all container networking.
- `host`: Gives the container raw access to the host's network interface.
- `service:{name}`: Gives the container access to the specified container by referring to its service name.
- `container:{name}`: Gives the container access to the specified container by referring to its container ID.
For more information container networks, see the [Docker Engine documentation](/manuals/engine/network/_index.md#container-networks).
```yml
network_mode: "host"
network_mode: "none"
network_mode: "service:[service name]"
```
When set, the [`networks`](#networks) attribute is not allowed and Compose rejects any
Compose file containing both attributes.
### `networks`
{{% include "compose/services-networks.md" %}}
```yml
services:
some-service:
networks:
- some-network
- other-network
```
For more information about the `networks` top-level element, see [Networks](networks.md).
### Implicit default network
If `networks` is empty or absent from the Compose file, Compose considers an implicit definition for the service to be
connected to the `default` network:
```yml
services:
some-service:
image: foo
```
This example is actually equivalent to:
```yml
services:
some-service:
image: foo
networks:
default: {}
```
If you want the service to not be connected a network, you must set [`network_mode: none`](#network_mode).
#### `aliases`
`aliases` declares alternative hostnames for the service on the network. Other containers on the same