Docker Community Forums

Share and learn in the Docker community.

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


#1

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 169.254.0.0 with Windows on 169.254.0.1
  • Docker Desktop Network configuration : 169.254.0.0 (255.255.0.0)
  • 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 169.254.0.2
  • 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 169.254.0.2.
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?


#3

Yes I am !
When I do ip addr inside my container, I got the IP 169.254.0.2 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 169.25.0.3 for example.


(Metin Y.) #4

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


#5

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 169.254.0.2 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…


#7

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 ?


#8

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.