Access private IP of other droplet in a Docker-instnace

Posted September 28, 2016 4.5k views
DockerNetworkingUbuntu 16.04

Hi there,

I have the following construction: Server 1 (mongod + app) and server 2 (just the app)
Both run their app inside Docker. I enabled private networking for both servers, and they are in the same region.

What I want to do is access the DB that’s installed on server, on server 2 using the private IP of server 1. I can do this without Docker but not inside.

I currently use the public (external) IP address. Does anyone know how to make this work? Thanks!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

You may need to specify the IP address when using the docker command to launch your container. instead of just adding a mapping of container port to host port you can also specify the IP address (in this case the host’s private IP).

docker run -p$HOSTPORT:$CONTAINERPORT --name CONTAINER -t someimage