# Docker Compose - Access host network interface

**URL:** <https://forums.docker.com/t/docker-compose-access-host-network-interface/67901>\
**Category:** Docker Hub\
**Tags:** docker\
**Created:** [January 27, 2019, 10:07pm UTC](https://forums.docker.com/t/docker-compose-access-host-network-interface/67901 "2019-01-27T22:07:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![abeillr](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@abeillr](https://forums.docker.com/u/abeillr)\
**Post date:** [January 27, 2019, 10:07pm UTC](https://forums.docker.com/t/docker-compose-access-host-network-interface/67901/1 "2019-01-27T22:07:50Z")

</div>

Good evening,

I would like to use a docker compose to create containers.

One of my container needs to access host network interface in order to use “ip addr” command on interface (to create a VIP, virtual ip address).

After a lot of research, I have found that I have to setup container with “host” network\_mode, to access host network interface.

My goal is to do not expose my container on host network, BUT being able to access host network interface.

Is there a way to get both options at the same time?

Thank you very much in advance,

BR,  
Rodolphe

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [January 28, 2019, 6:32am UTC](https://forums.docker.com/t/docker-compose-access-host-network-interface/67901/2 "2019-01-28T06:32:06Z")

</div>

> [@abeillr](#):
>
> One of my container needs to access host network interface in order to use “ip addr” command on interface (to create a VIP, virtual ip address).
> 
> After a lot of research, I have found that I have to setup container with “host” network\_mode, to access host network interface.

You might take a look at the Github sources of images that already tackled the VIP problem, for instance [GitHub - NeoAssist/docker-keepalived: Dockerized keepalived to ease HA in deployments with multiple hosts. Provides failover for Virtual IPs (VIP) to be always online even if a host fails. Initially aimed to help Rancher HA deployments](https://github.com/NeoAssist/docker-keepalived)

> [@abeillr](#):
>
> My goal is to do not expose my container on host network, BUT being able to access host network interface.
> 
> Is there a way to get both options at the same time?

Aren’t those contradicting requirements? Either you bind your container to the host network interface or you don’t…

---

<div class="post-metadata">

**Author:** ![abeillr](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@abeillr](https://forums.docker.com/u/abeillr)\
**Post date:** [January 28, 2019, 9:28am UTC](https://forums.docker.com/t/docker-compose-access-host-network-interface/67901/3 "2019-01-28T09:28:20Z")

</div>

The thing is that if I setup my container on host network, I will not be able to access other containers if they are on “bridge” network, right?  
I don’t want to share ports of all my containers on host network (a database server shouldn’t be reachable on host, but only from other containers).  
But the container which controls the VIP has to be able to reach database.  
So the question is:  
If I want to control my host network interface, I have to set ALL my containers on “HOST” network mode? (because if not, they will not be able to communicate each other anymore)

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [January 28, 2019, 5:36pm UTC](https://forums.docker.com/t/docker-compose-access-host-network-interface/67901/4 "2019-01-28T17:36:19Z")

</div>

frankly, i am unclear about the effect. Though, try declaring two networks and using the same network in the containers that should interact with each other and the other one strictly for frontend communication.

But the usecase for a nginx reverse proxy running in host mode and sending traffic to containers in a backend network ist not that uncommon. Just try and see 🙂

---

<div class="post-metadata">

**Author:** ![abeillr](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@abeillr](https://forums.docker.com/u/abeillr)\
**Post date:** [January 28, 2019, 5:45pm UTC](https://forums.docker.com/t/docker-compose-access-host-network-interface/67901/5 "2019-01-28T17:45:37Z")

</div>

The thing is that it is not possible to create a network which has access to host network interface…

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [January 28, 2019, 6:00pm UTC](https://forums.docker.com/t/docker-compose-access-host-network-interface/67901/6 "2019-01-28T18:00:14Z")

</div>

Ah, now we are getting somewhere.

Well, one solution might be to create a macvlan network that uses a subset of your local lan, which is NOT handled by the networks DHCP Server. I am sure the search function will reveal some examples on how it’s created.

Then you declare a bridged network, which you only use for communication between containers.

---

<div class="post-metadata">

**Author:** ![abeillr](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@abeillr](https://forums.docker.com/u/abeillr)\
**Post date:** [January 29, 2019, 7:41am UTC](https://forums.docker.com/t/docker-compose-access-host-network-interface/67901/7 "2019-01-29T07:41:22Z")

</div>

First, thank you very much for your help.  
Macvlan needs additional ip address on the LAN, but I am restricted to 1 address for Docker machine 😟

---

<div class="post-metadata">

**Author:** ![abeillr](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@abeillr](https://forums.docker.com/u/abeillr)\
**Post date:** [February 1, 2019, 1:21pm UTC](https://forums.docker.com/t/docker-compose-access-host-network-interface/67901/8 "2019-02-01T13:21:34Z")

</div>

[Bump] Any idea on this topic? ☹

---

<div class="post-metadata">

**Author:** ![abeillr](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@abeillr](https://forums.docker.com/u/abeillr)\
**Post date:** [February 15, 2019, 7:57am UTC](https://forums.docker.com/t/docker-compose-access-host-network-interface/67901/9 "2019-02-15T07:57:44Z")

</div>

I have still no clue, any help? 😔
