2017-01-16 52 views
0

docker-compose.yml文件中,- "3000"- "3000:3000"有什麼不同?從文檔看來,它們是相同的。但是,第一種格式確實是而不是開放端口到主機。在docker-compose文件中映射端口時需要第二個值嗎?

ports: 
- "3000" 
- "3000-3005" 
- "8000:8000" 
- "9090-9091:8080-8081" 
- "49100:22" 
- "127.0.0.1:8001:8001" 
- "127.0.0.1:5000-5010:5000-5010" 

我使用的網站上的官方多克爾文檔:here

回答

1

從文檔:

請指定兩個端口(HOST:CONTAINER),或者只是貨櫃碼頭(一隨機主機端口將被選中)。

當您只指定一個端口時,您需要使用ps檢查容器或檢查主機端是否打開了哪個端口。

$ cat docker-compose.yml 
version: '2' 

services: 
    web: 
    image: nginx:latest 
    volumes: 
    - ./html:/usr/share/nginx/html 
    ports: 
    - "80" 

$ docker-compose up -d 
Creating network "test_default" with the default driver 
Creating test_web_1 

$ docker-compose ps 
    Name   Command   State    Ports 
-------------------------------------------------------------------------- 
test_web_1 nginx -g daemon off; Up  443/tcp, 0.0.0.0:32769->80/tcp 

$ curl http://localhost:32769 
<html><body>hello world</body></html> 
相關問題