2016-04-20 128 views
0

我剛剛安裝使用的NodeJS碼頭工人,和我運行一個測試服務器:如何在主機上運行本地服務器?

docker exec -i -t my-running-app bash 
[email protected]:/usr/src/app# npm start 
npm info it worked if it ends with ok 
npm info using [email protected] 
npm info using [email protected] 
npm info prestart [email protected] 
npm info start [email protected] 

> [email protected] start /usr/src/app 
> node server.js 

Server running at http://127.0.0.1:8000/ 

在泊塢窗的形象,我露出端口8000,但我不知道我怎麼會瀏覽到節點服務器從主機內部容器?

,如果我只是瀏覽http://127.0.0.1:8000/我得到:

This site can’t be reached 

127.0.0.1 refused to connect. 

我在Ubuntu 14.04,所以,我將如何查看deckorized服務器?

+0

嘗試8000端口上的容器的IP地址,類似於http ://172.1.2.3:8000 – user2915097

+0

你是如何公開端口8000,你可以發佈你的碼頭配置 –

回答

0

首先嚐試把所有的容器啓動命令Dockerfile(你建立你的泊塢窗圖像),即你需要npm start和暴露端口8000,您應該添加到Dockerfile :

EXPOSE 8000 
CMD [ "npm", "start" ] 

您需要啓動你的端口映射應用程序實例:

docker run -p public_port:8000 -d my-running-app 

這將創建一個從「外部」世界通信隧道(public_port,可以是相同的 - 8000,或任何你需要的),以泊塢窗圖像

0

您需要在容器端口映射到主機端口:

docker exec -p 8000:3000 

例如你的8000集裝箱港口映射到你的3000主機端口。

By default Docker containers can make connections to the outside world, but the outside world cannot connect to containers. Each outgoing connection will appear to originate from one of the host machine’s own IP addresses thanks to an iptables masquerading rule on the host machine that the Docker server creates when it starts..

Docker doc for binding Ports

+0

我試圖碼頭執行程序-p 8000:3000 -i -t我的運行應用程序bash,但我得到錯誤:標誌提供但沒有定義:-p – simo

相關問題