> For the complete documentation index, see [llms.txt](https://philipzheng.gitbook.io/docker_practice/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://philipzheng.gitbook.io/docker_practice/advanced_network.md).

# 進階網路設定

本章將介紹 Docker 的一些進階網路設定和選項。

當 Docker 啟動時，會自動在主機上建立一個 `docker0` 虛擬橋接器，實際上是 Linux 的一個 bridge，可以理解為一個軟體交換機。它會在掛載到它的網卡之間進行轉發。

同時，Docker 隨機分配一個本地未占用的私有網段（在 [RFC1918](http://tools.ietf.org/html/rfc1918) 中定義）中的一個位址給 `docker0` 介面。比如典型的 `172.17.42.1`，網路遮罩為 `255.255.0.0`。此後啟動的容器內的網卡也會自動分配一個同一網段（`172.17.0.0/16`）的網址。

當建立一個 Docker 容器的時候，同時會建立了一對 `veth pair` 介面（當資料包發送到一個介面時，另外一個介面也可以收到相同的資料包）。這對介面一端在容器內，即 `eth0`；另一端在本地並被掛載到 `docker0` 橋接器，名稱以 `veth` 開頭（例如 `vethAQI2QT`）。透過這種方式，主機可以跟容器通訊，容器之間也可以相互通訊。Docker 就建立了在主機和所有容器之間一個虛擬共享網路。

![Docker 網路](/files/-LvLdneHNQuU79ne0TM_)

接下來的部分將介紹在一些場景中，Docker 所有的網路自訂設定。以及透過 Linux 命令來調整、補充、甚至替換 Docker 預設的網路設定。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://philipzheng.gitbook.io/docker_practice/advanced_network.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
