简体   繁体   中英

expose docker containers application port to host on windows using boot2docker

So far I have:

  1. installed boot2docker 1.6.0 on WIN7
  2. created a container using ubuntu:14.01 base image
  3. installed an application and committed it so that now I have a new image "demotest_core"

The issue that I am running into is that when I start my container using this command

docker run -it --name demotest --rm -p 127.0.0.1:15000:1500 -v /c/Users/b101/shared:/mnt/shared ubuntu/demotest_core bin/bash

the container starts, after that I cd to my application's dir and start the application (its a web application that runs on port 1500) the application starts successfully on the container and I can see it in LISTENING mode when I do netstat . I would like to access this app on my host WIN7 system but when I try http://127.0.0.1:15000 I get connection refused error.

Using another terminal I can clearly see that the port mapping is in place but I am not able to access it on the host

C:\Users\b101>docker port demotest
1500/tcp -> 127.0.0.1:15000

I have also tried this command thinking that first I need to expose the PORT and then MAP it but it didn't work

docker run -it --name demotest --expose 1500 --rm -p 127.0.0.1:15000:1500 -v /c/Users/b101/shared:/mnt/shared ubuntu/demotest_core bin/bash

If you're using docker-machine, that port is exposed in the VM, not your local Win7 machine.

Change -p 127.0.0.1:15000:1500 to just 15000:1500 and then try accessing port 15000 at the IP Address given at docker-machine ip default .

You can't use 127.0.0.1 in the port mapping as that will only bind to the local interface which won't be accessible from outside the VM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM