Skip to content

Instantly share code, notes, and snippets.

@dannynash
Created December 16, 2017 03:03
Show Gist options
  • Save dannynash/358368bb3c71a84332f8a3984ec2ad49 to your computer and use it in GitHub Desktop.
Save dannynash/358368bb3c71a84332f8a3984ec2ad49 to your computer and use it in GitHub Desktop.
初探 docker network,目標是要讓 container 內的服務可以透過 http 與 host 上的 server 溝通
docker network 分成三個等級
### bridge
docker0, default
you can only configure the default bridge network
### none
container-specific network stack
### host
host’s network stack
## 實際測試
https://forums.docker.com/t/accessing-host-machine-from-within-docker-container/14248/9
根據上面討論串,可以自己建立 customize network:
```
docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 dockernet
```
執行 container:
```
docker run --net=dockernet {image}
```
在 container 內的確可以透過 192.168.0.1 跟 host 上的 server 溝通。
但是在 OSX 卻不能這麼做,可能跟 kevinpmcc 評論裡說的有關連。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment