Jump to content

How to use the host's IP Address inside a Docker container


Recommended Posts

Posted

I know this isn't news, but it was new to me and I didn't see a post in here regarding this directly so hopefully this will help people as well.

Basically when you want one docker to talk to another docker what IP do you give it.  In my case I was using a Static IP because LOCALHOST doesn't work and if you have a potentially dynamic IP what do you do?

 

I stumbled across this article https://dev.to/natterstefan/docker-tip-how-to-get-host-s-ip-address-inside-a-docker-container-5anh which let me know that in Linux you can use "172.17.0.1" to achieve this.  (Windows/Mac Dockers uses "gateway.docker.internal".  For some reason Linux is unique)

 

It was really helpful for me and hopefully this was titled in such a way that others find it when they encounter the same issue.

 

Posted
I know this isn't news, but it was new to me and I didn't see a post in here regarding this directly so hopefully this will help people as well.
Basically when you want one docker to talk to another docker what IP do you give it.  In my case I was using a Static IP because LOCALHOST doesn't work and if you have a potentially dynamic IP what do you do?
 
I stumbled across this article https://dev.to/natterstefan/docker-tip-how-to-get-host-s-ip-address-inside-a-docker-container-5anh which let me know that in Linux you can use "172.17.0.1" to achieve this.  (Windows/Mac Dockers uses "gateway.docker.internal".  For some reason Linux is unique)
 
It was really helpful for me and hopefully this was titled in such a way that others find it when they encounter the same issue.
 
If the 2 containers are in the same network, then you can use the name of the containers as hostnames to communicate between them.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...