Update content

This commit is contained in:
khs1994
2017-11-26 11:28:55 +08:00
parent 50ed70f29b
commit b0e5d9894a
3 changed files with 18 additions and 13 deletions

View File

@@ -1,16 +1,14 @@
## 配置 DNS
Docker 没有为每个容器专门定制镜像,那么怎么自定义配置容器的主机名和 DNS 配置呢?
秘诀就是它利用虚拟文件来挂载到来容器的 3 个相关配置文件。
如何自定义配置容器的主机名和 DNS 呢?秘诀就是 Docker 利用虚拟文件来挂载容器的 3 个相关配置文件。
在容器中使用 `mount` 命令可以看到挂载信息:
在容器中使用 mount 命令可以看到挂载信息:
```bash
$ mount
...
/dev/disk/by-uuid/1fec...ebdf on /etc/hostname type ext4 ...
/dev/disk/by-uuid/1fec...ebdf on /etc/hosts type ext4 ...
tmpfs on /etc/resolv.conf type tmpfs ...
...
```
这种机制可以让宿主主机 DNS 信息发生更新后,所有 Docker 容器的 DNS 配置通过 `/etc/resolv.conf` 文件立刻得到更新。
@@ -37,12 +35,9 @@ nameserver 8.8.8.8
如果用户想要手动指定容器的配置,可以利用下面的选项。
`-h HOSTNAME or --hostname=HOSTNAME`
设定容器的主机名,它会被写到容器内的 `/etc/hostname``/etc/hosts`。但它在容器外部看不到,既不会在 `docker ps` 中显示,也不会在其他的容器的 `/etc/hosts` 看到。
`-h HOSTNAME` 或者 `--hostname=HOSTNAME` 设定容器的主机名,它会被写到容器内的 `/etc/hostname``/etc/hosts`。但它在容器外部看不到,既不会在 `docker ps` 中显示,也不会在其他的容器的 `/etc/hosts` 看到。
`--dns=IP_ADDRESS`
添加 DNS 服务器到容器的 `/etc/resolv.conf` 中,让容器用这个服务器来解析所有不在 `/etc/hosts` 中的主机名。
`--dns=IP_ADDRESS` 添加 DNS 服务器到容器的 `/etc/resolv.conf` 中,让容器用这个服务器来解析所有不在 `/etc/hosts` 中的主机名。
`--dns-search=DOMAIN`
设定容器的搜索域,当设定搜索域为 `.example.com` 时,在搜索一个名为 host 的主机时DNS 不仅搜索host还会搜索 `host.example.com`
`--dns-search=DOMAIN` 设定容器的搜索域,当设定搜索域为 `.example.com` 时,在搜索一个名为 host 的主机时DNS 不仅搜索 host还会搜索 `host.example.com`
注意:如果没有上述最后 2 个选项Docker 会默认用主机上的 `/etc/resolv.conf` 来配置容器。