Docker Community Forums

Share and learn in the Docker community.

Accessing host machine from within docker container


(Kostyavyrodov) #22

What if your docker works with linux?

(Qoomon) #23

Docker Container to access host ports =>

(Realdubb) #24

This worked ! Thank you

(Clns) #25

Yes, same issue here and a valid use case.

(Mosen11) #26

I try to access my mongoDB on host by the container but I get the following exception: Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.DefaultServerMonitor$
Caused by: Connection refused (Connection refused)
at Method)
at com.mongodb.connection.SocketStreamHelper.initialize(
I run my container with this command: docker run --network=“host” 659004210509. I try several variation but none of them worked.

(Kensai) #27

As per this page you can also use host.docker.internal as a platform-agnostic way to reference the host.


I thought you were going to be my hero… but as per the very next sentence on that page,

This is for development purpose and will not work in a production environment outside of Docker for Windows.

EDIT: I see the same comment in the Mac docs saying the same thing, all as of 18.03, however I have 18.07 and that does not resolve.

(Ognyan Dimitrov) #29

Can you use environment variables for that matter? You can write any host information (the host ip) in a variable and pass it to the container the moment you run it.

(Gary Forghetti) #30

Yes, check this post.