简体   繁体   中英

How can I access from outside my docker container in mac?

I have a docker container running in a default vm in mac, I've already mapped the ports of my particular application to the ports of the vm. Once I've done that I can access my application by doing:

curl $(docker-machine ip default):9003

After that I've mapped my vm port to my localhost by doing port forwarding this way:

VBoxManage controlvm default natpf1 "9003,tcp,127.0.0.1,9003,,9003"

Once I've done that I get a response of my application from my localhost

curl localhost:9003

My question is: How can I access this application from the outside world or even from my own network? I've tried opening a port in my mac with:

pass in inet proto tcp from any to any port 9003

but still the port shows as closed with nmap. Does anyone knows what I'm missing?

You can either bind your socket to localhost if the docker-run option --net=host is used, hence the local stack, as well as NICs, are shared between the host and the container(s).

OTOH, if the docker-run option -p is used then if the socket is bound to a localhost IP address then the service cannot be accessed from outside the container.


Wait for the answer of @marc-b though, he gave it the first.

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