Home Explore Blog CI



docker

5th chunk of `content/manuals/engine/network/_index.md`
f1462b6be571ebfb58fca4ceff3ed3f669e11b5046b054380000000100000b7b
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                                                                                                                                                                                                                                           |
| -------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `--dns`        | The IP address of a DNS server. To specify multiple DNS servers, use multiple `--dns` flags. DNS requests will be forwarded from the container's network namespace so, for example, `--dns=127.0.0.1` refers to the container's own loopback address. |
| `--dns-search` | A DNS search domain to search non-fully qualified hostnames. To specify multiple DNS search prefixes, use multiple `--dns-search` flags.                                                                                                              |
| `--dns-opt`    | A key-value pair representing a DNS option and its value. See your operating system's documentation for `resolv.conf` for valid options.                                                                                                              |
| `--hostname`   | The hostname a container uses for itself. Defaults to the container's ID if not specified.                                                                                                                                                            |

### Custom hosts

Your container will have lines in `/etc/hosts` which define the hostname of the
container itself, as well as `localhost` and a few other common things. Custom
hosts, defined in `/etc/hosts` on the host machine, aren't inherited by
containers. To pass additional hosts into a container, refer to [add entries to
container hosts file](/reference/cli/docker/container/run.md#add-host) in the
`docker run` reference documentation.

## Proxy server

If your container needs to use a proxy server, see
[Use a proxy server](/manuals/engine/daemon/proxy.md).

Title: Detailed DNS Configuration and Custom Hosts for Docker Containers
Summary
This section provides an in-depth look at DNS configuration for Docker containers, explaining that containers initially use the host's DNS settings defined in `/etc/resolv.conf`. Containers on the default `bridge` network receive a copy of this file, while those on custom networks utilize Docker's embedded DNS server. The section details how to configure DNS resolution per-container using `docker run` flags like `--dns`, `--dns-search`, and `--dns-opt`. It also addresses custom hosts, explaining that entries in the host's `/etc/hosts` file are not inherited and directs users to the `docker run` documentation for adding custom entries. Finally, it refers users to separate documentation on using proxy servers with containers.