docker / docker/docker-py

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

Open
#2,355 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/enhancement kind/question level/dockerclient
Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the container creation and network.connect() calls shown in the issue, comparing their behavior with the docker run command and Docker Engine API networking semantics. Verify how the requested static IPv4 address and host port mapping are represented, and consider the work complete when the container retains 172.21.0.21 while exposing the specified UDP port.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.