I created a network with driver: ipvlan and several subnets with specific gateways in it. (about 20)
Now i want to create containers with specific IP's, so that they get assign to the right subnet of the ipvlan network only!
dockernetwork = client.networks.get('ipvlan172')
print "create container with ip "+targetIP
client.containers.run('myalpine',auto_remove=True,command='ping 192.168.11.11',detach=True,name=targetName)
dockernetwork.connect(container,ipv4_address=targetIP)
container.start()
What happens here is, that client.containers.run give the container an ip of the docker bridge network and the default gateway to the docker bridge. Then dockernetwork.connect gives the container's interface a second ip (target ip).
If i add the parameter network='ipvlan172' to the command:
client.containers.run('myalpine',network='ipvlan172',auto_remove=True,command='ping 192.168.11.11',detach=True,name=targetName)
The created container does not get an ip of the docker bridge network, which i intended, but the targetIP of the command
dockernetwork.connect(container,ipv4_address=targetIP)
will be ignored. So that the created Container has an IP of a random subnet of the ipvlan network
One way to solve this, is to create a script which will be executed after the start of the container and deletes the dockerhost ip and changes the default gateway.
Are there other solutions?
Thanks!