Docker Community Forums

Share and learn in the Docker community.

How to set the IP of my Linux container started with --network=host?


Hello, my setup is:

  • Windows 10 host (Docker Desktop 18.09.1 / Hyper-V / MobyLinuxVM)
  • On this host, a network adapter to create a LAN on subnet with Windows on
  • Docker Desktop Network configuration : (
  • Some modifications in C:\Program Files\Docker\Docker\resources\MobyLinux.ps1 to have MobyLinux use an External switch attached to the network adapter. See this post.
  • Linux container (centos) started with network=host

With this setup:

  • I got a Linux container in the same LAN as Windows host, with IP
  • I can ping Linux from Windows and reversely.
  • I can share a directory.

But if I create a second container with the same image, I got the same IP
How can I change that ? Which rule is used by the engine to set this IP address ?
Thanks for help.

(Metin Y.) #2

Are you aware that using --network=host results in using the hosts network?


Yes I am !
When I do ip addr inside my container, I got the IP which is in the same subnetwork as the host but with a different IP address.
That suits my needs for this first container but not for the second which get the same IP as the first. I would like that the second get the IP for example.

(Metin Y.) #4

You expectation on how network=host works contradicts with how it is designed to work. It works as desgined.


Ok, even if I don’t understant the logic behind that.
I would understand the logic if my container got the same IP as the host but the fact is that it didn’t got the same.
Is the IP is depending on a docker-machine which would handle both containers ?
Thanks a lot for your patience !

(Metin Y.) #6

On Hyper-V containers are not run nativly on your host, but on a “remote” docker engine inside a linux vm. So the ip you see is the host ip of that particular “host” vm that runs the docke engine.

You expect the linux vm to claim the host windows ip…


Tanks for this answer which clarify my comprehension.
A last question : do you think it is possible for Hyper-V to start a second “particular host" (as you said) and start a linux container with it ? Hoping this way that I could have that container having another IP ?


I just see this link. This link gives me an answer to my question which is: not possible using MobyLiuxVM.

Thank you for your help. I am going to try LCOW.