# Docker的網路

Docker 的網路

透過 Linux 的網路命名空間與虛擬網路裝置(Veth pair)實現而成。然而 Docker 的網路支援了不同類型功能，主要分為四大項：

* Bridge Mode (預設)
* Host Mode
* None Mode
* Container Mode

## 檢視目前 Docker Network 狀態 <a href="#jian-shi-mu-qian-dockernetwork-zhuang-tai" id="jian-shi-mu-qian-dockernetwork-zhuang-tai"></a>

docker network ls

![](https://529150212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lh81JtaIQ84bwQqz_Wh%2F-Lk1V6eXL8rA2-BLzI17%2F-Lk1ZxTE0fN9Y6kCeAZK%2Fimage.png?alt=media\&token=dd653604-0bc1-478c-87fc-691edbd07f99)

使用 portainer WEBUI檢視:

![](https://529150212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lh81JtaIQ84bwQqz_Wh%2F-Lk1V6eXL8rA2-BLzI17%2F-Lk1ZklwuCJtssBRdwUh%2Fimage.png?alt=media\&token=6aef323f-0984-44bb-9bb0-8d8b73151156)

Bridge Mode的模式如下圖

![](https://529150212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lh81JtaIQ84bwQqz_Wh%2F-Lk1T6fg1_ZbLb7k--TF%2F-Lk1T9V2wWcKZWRSpyQy%2Fimage.png?alt=media\&token=46bdda8d-d6de-4b57-b391-241724f9eac4)

### &#x20;<a href="#bridge-mode" id="bridge-mode"></a>

## Host Mode

Host Mode 可以把他想像成建立一個與 Host 擁有同樣的 network interface 的 Container ，使用方式：

```
docker run --net=host -it busybox sh
```

### None Mode <a href="#none-mode" id="none-mode"></a>

None Mode 是建置最簡潔的 Container ，也就是沒有任何 network interface 的 Container。使用方式是在建立 Container 的同時給與 `--net=none` 的參數

```
docker run --net=none -it busybox sh
```

### Container Mode <a href="#container-mode" id="container-mode"></a>

先啟動一個 Container，並且使用這個 Container 的 Container ID 建立另外一個 Container容器:

```
docker run --name hello -id busybox sh
docker ps
CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS              PORTS                    NAMES
5615119a0082        busybox               "sh"                5 seconds ago       Up 2 seconds                                 hello
```

![](https://529150212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lh81JtaIQ84bwQqz_Wh%2F-LkM7vPMMf091Ovt6v_8%2F-LkM9lBBa1bLZdtEsvzd%2Fimage.png?alt=media\&token=bd0cc8cb-dd78-4877-a884-5aa807fe3547)

```
docker run -ti --net=container:(hello | 或5615119a0082) busybox sh
```

![](https://529150212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lh81JtaIQ84bwQqz_Wh%2F-LkM7vPMMf091Ovt6v_8%2F-LkM9eNPghp-0YfRydwC%2Fimage.png?alt=media\&token=cac691b3-3965-4745-a65b-ecf65a90a9ec)


---

# Agent Instructions: 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:

```
GET https://kawsing.gitbook.io/opensystem/docker-cong-an-zhuang-dao-ying-yong-ru-men-pian/docker-de-wang-lu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
