Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to connect Docker container to local host

I am wondering if is it possible to connect to an app on local host from Docker container.

I run two Docker container which are connected to each other via link option. But how can I connect one of the containers to the local host?

like image 983
rset_d Avatar asked Sep 14 '25 14:09

rset_d


1 Answers

Yes, use docker run --network=container:<container-id>

--network='container:': reuse another container's network stack

This let you run a container sharing the same network interface (then localhost) from another container.


Alternatively, you can use the host mode to give your containers the same network ips that the host has (including localhost). docker run --network=host:

--network= 'host': use the Docker host network stack

Docs: https://docs.docker.com/engine/reference/run/#name-name

like image 110
Robert Avatar answered Sep 16 '25 08:09

Robert