国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 服務器 > Web服務器 > 正文

Docker 端口映射詳細介紹

2024-09-01 13:48:32
字體:
來源:轉載
供稿:網(wǎng)友

Docker 端口映射:

         最近抽空,把Docker 端口映射的資料整理了一下,以便后續(xù)項目應用,大家也可以參考下。  

# Find IP address of container with ID <container_id> 通過容器 id 獲取 ip $ sudo docker inspect <container_id> | grep IPAddress | cut -d '"' -f 4

無論如何,這些 ip 是基于本地系統(tǒng)的并且容器的端口非本地主機是訪問不到的。此外,除了端口只能本地訪問外,對于容器的另外一個問題是這些 ip 在容器每次啟動的時候都會改變。
Docker 解決了容器的這兩個問題,并且給容器內部服務的訪問提供了一個簡單而可靠的方法。Docker 通過端口綁定主機系統(tǒng)的接口,允許非本地客戶端訪問容器內部運行的服務。為了簡便的使得容器間通信,Docker 提供了這種連接機制。

5.1 自動映射端口

-P使用時需要指定--expose選項,指定需要對外提供服務的端口

$ sudo docker run -t -P --expose 22 --name server  ubuntu:14.04

使用docker run -P自動綁定所有對外提供服務的容器端口,映射的端口將會從沒有使用的端口池中 (49000..49900) 自動選擇,你可以通過docker ps、docker inspect <container_id>或者docker port <container_id> <port>確定具體的綁定信息。

5.2 綁定端口到指定接口

基本語法

$ sudo docker run -p [([<host_interface>:[host_port]])|(<host_port>):]<container_port>[/udp] <image> <cmd>

默認不指定綁定 ip 則監(jiān)聽所有網(wǎng)絡接口。

 綁定 TCP 端口

# Bind TCP port 8080 of the container to TCP port 80 on 127.0.0.1 of the host machine. $ sudo docker run -p 127.0.0.1:80:8080 <image> <cmd> # Bind TCP port 8080 of the container to a dynamically allocated TCP port on 127.0.0.1 of the host machine. $ sudo docker run -p 127.0.0.1::8080 <image> <cmd> # Bind TCP port 8080 of the container to TCP port 80 on all available interfaces of the host machine. $ sudo docker run -p 80:8080 <image> <cmd> # Bind TCP port 8080 of the container to a dynamically allocated TCP port on all available interfaces $ sudo docker run -p 8080 <image> <cmd>

綁定 UDP 端口

# Bind UDP port 5353 of the container to UDP port 53 on 127.0.0.1 of the host machine. $ sudo docker run -p 127.0.0.1:53:5353/udp <image> <cmd>

 感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 锦州市| 三台县| 玉环县| 岑巩县| 邢台市| 视频| 宜州市| 清丰县| 秦皇岛市| 腾冲县| 宜兰市| 东宁县| 宝应县| 清水河县| 泰州市| 仁布县| 钟祥市| 甘泉县| 唐河县| 顺义区| 呈贡县| 福海县| 虎林市| 顺平县| 丹江口市| 荥阳市| 丁青县| 锡林浩特市| 巩义市| 大洼县| 灵石县| 文登市| 上林县| 文昌市| 涟水县| 张家口市| 灵宝市| 从化市| 孟村| 翁牛特旗| 河津市|