mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-03-26 19:55:23 +00:00
Remove blank lines after code block markers
This commit is contained in:
@@ -18,7 +18,6 @@ Docker 容器的 DNS 配置有两种情况:
|
||||
这是 Docker 网络最强大的功能之一。在自定义网络中,容器可以通过 “名字” 找到彼此,而不需要知道对方的 IP (因为 IP 可能会变)。
|
||||
|
||||
```bash
|
||||
|
||||
## 1. 创建自定义网络
|
||||
|
||||
$ docker network create mynet
|
||||
@@ -33,7 +32,6 @@ $ docker run -it --rm --network mynet alpine ping web
|
||||
PING web (172.18.0.2): 56 data bytes
|
||||
64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.074 ms
|
||||
```
|
||||
|
||||
**原理**:
|
||||
Docker 守护进程在 `127.0.0.11` 运行了一个 DNS 服务器。容器内的 DNS 请求会被转发到这里。如果是容器名,解析为容器 IP;如果是外部域名 (如 google.com),转发给上游 DNS。
|
||||
|
||||
@@ -51,7 +49,6 @@ Docker 守护进程在 `127.0.0.11` 运行了一个 DNS 服务器。容器内的
|
||||
$ docker run -it --dns=114.114.114.114 ubuntu cat /etc/resolv.conf
|
||||
nameserver 114.114.114.114
|
||||
```
|
||||
|
||||
#### 2. --dns-search
|
||||
|
||||
指定 DNS 搜索域。例如设置为 `example.com`,则 `ping host` 会尝试解析 `host.example.com`。
|
||||
@@ -59,7 +56,6 @@ nameserver 114.114.114.114
|
||||
```bash
|
||||
$ docker run --dns-search=example.com myapp
|
||||
```
|
||||
|
||||
#### 3. --hostname 与 -h
|
||||
|
||||
设置容器的主机名。
|
||||
@@ -67,7 +63,6 @@ $ docker run --dns-search=example.com myapp
|
||||
```bash
|
||||
$ docker run -h myweb nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 9.1.4 全局 DNS 配置
|
||||
@@ -82,7 +77,6 @@ $ docker run -h myweb nginx
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
修改后需要重启 Docker 服务:`systemctl restart docker`。
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user