Skip to content

Fail to assign staticip along with portmapping to container using docker-py #2355

Open
@gururajsrk

Description

@gururajsrk

Hi,

I have issue and could not find solution regarding this
Use case:
Trying to assign a static ip from a network to a container and same ip has to be used for portmapping to host network
I am able to achieve this from binary but not from docker.py library

      docker run -it --name container --net radio --ip 172.21.0.20  -p 192.168.0.13:5554:5554/udp  imagename

in code I am creating container

              key=("%s/%s" % (self.port,self.protocol))
              cportmapping = { key  : (self.ip, self.port)}   # {  '5554/udp' : (192.168.0.13,5554)}
              argd['ports']=self.cportmapping
              argd['network'] = self.cnetwork  (network = radio)
              container=self.client.containers.create(self.cimagename,detach=True,**argd)
              network.connect(containerid,ipv4_address=self.networkstaticip) (networkstaticip =172.21.0.21)

Even though i have provided a static ip, it wont use this static called using connect(). It only assigns random ip provided from network radio pool. Can someone help me on this

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions