Home Explore Blog CI



docker

4th chunk of `content/manuals/engine/network/_index.md`
e6f30aac4964a99b44cac9a4aa4399d5f073cb71ee12b8b60000000100000923
[packet filtering and firewalls](./packet-filtering-firewalls.md).

## IP address and hostname

When creating a network, IPv4 address allocation is enabled by default, it
can be disabled using `--ipv4=false`. IPv6 address allocation can be enabled
using `--ipv6`.

```console
$ docker network create --ipv6 --ipv4=false v6net
```

By default, the container gets an IP address for every Docker network it attaches to.
A container receives an IP address out of the IP subnet of the network.
The Docker daemon performs dynamic subnetting and IP address allocation for containers.
Each network also has a default subnet mask and gateway.

You can connect a running container to multiple networks,
either by passing the `--network` flag multiple times when creating the container,
or using the `docker network connect` command for already running containers.
In both cases, you can use the `--ip` or `--ip6` flags to specify the container's IP address on that particular network.

In the same way, a container's hostname defaults to be the container's ID in Docker.
You can override the hostname using `--hostname`.
When connecting to an existing network using `docker network connect`,
you can use the `--alias` flag to specify an additional network alias for the container on that network.

## DNS services

Containers use the same DNS servers as the host by default, but you can
override this with `--dns`.

By default, containers inherit the DNS settings as defined in the
`/etc/resolv.conf` configuration file.
Containers that attach to the default `bridge` network receive a copy of this file.
Containers that attach to a
[custom network](tutorials/standalone.md#use-user-defined-bridge-networks)
use Docker's embedded DNS server.
The embedded DNS server forwards external DNS lookups to the DNS servers configured on the host.

You can configure DNS resolution on a per-container basis, using flags for the
`docker run` or `docker create` command used to start the container.
The following table describes the available `docker run` flags related to DNS
configuration.

| Flag           | Description                                                                                                                                                                                                                                           |

Title: IP Address, Hostname, DNS Configuration for Docker Containers
Summary
This section discusses IP address allocation and hostname assignment in Docker networks. It explains that IPv4 address allocation is enabled by default but can be disabled, and IPv6 allocation can be enabled. Containers get an IP address for each network they attach to, and the Docker daemon handles dynamic subnetting. You can connect containers to multiple networks and specify IP addresses using flags. The hostname defaults to the container ID but can be overridden. It also explains how containers use the host's DNS servers by default, but this can be overridden using flags, and how custom networks utilize Docker's embedded DNS server.