简体   繁体   中英

How to expose docker container only to private network

Not sure if it's a machine or docker configuration problem.

I have a VM with public IP (176.X.XXX.XXX) and private IP (10.X.XXX.XXX) and I'd like other VMs to access my container through private IP as they are in the same network.

So I do

    ports:
        - "10.X.XXX.XXX:9200:9200"

but this exposes the port to 176.X.XXX.XXX as well, which is not desired.

and when I expose it to localhost only

    ports:
        - "127.0.0.1:9200:9200"

I can't access it from other VMs on the private network.

This is most probably because of either

  • This is an aws/gcp/azure/droplet/etc instance in which case the cloud provider NATs the public IP address to the private IP address
  • You have managed to NAT the public IP address to private IP address explicitly for some reason

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