moby / moby/libnetwork

Adding an ip in the same range as an existing ip replaces the original IP.

Open
#1,696 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
2.2k
Forks
875
PR merge metrics
No merged PRs in 30d

Description

When I attempt to add a second ip address to my docker container in the same docker macvlan network, using the create, docker network connect, start pattern it appears to override the first ip address assigned during the 'create' step.

Steps to reproduce:

  1. Create a docker macvlan network:
    docker network create -d macvlan \
        --subnet=192.168.100.1/24 \
        -o parent=eth0 pub_net

  1. Create a docker container from an image, adding an ip address from the subnet to the container:
    docker create \
        --network pub_net \
        --ip=192.168.100.2 \
	    -h mycontainer \
	    --name mycontainer \
        -ti \
        alpine \
        /bin/sh

  1. Add a second ip address with an alias to the container
docker network connect \
      --ip 192.168.100.3 \
      --alias mycontainer-int2 \
      pub_net \
      mycontainer

(and just to be sure, the result of this command was 0 - success)

    $ echo $?
    0
  1. Run it and open it to have a look
    $ docker start mycontainer
    mycontainer
    $ docker attach mycontainer
    / # ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
    10: eth0@if2: <NO-CARRIER,BROADCAST,MULTICAST,UP,M-DOWN> mtu 1500 qdisc noqueue state LOWERLAYERDOWN 
        link/ether 02:42:c0:a8:c8:03 brd ff:ff:ff:ff:ff:ff
        inet 192.168.100.3/24 scope global eth0
       valid_lft forever preferred_lft forever
    / # 

It only shows the second IP address on the interface.

And...just to be sure:

  $ docker network inspect pub_net
   [
       {
           "Name": "pub_net",
           "Id": "578df6fd9929b0c44356e32a04043b358c2a052e11377ee7430743cd48566203",
           "Scope": "local",
           "Driver": "macvlan",
           "EnableIPv6": false,
           "IPAM": {
               "Driver": "default",
               "Options": {},
               "Config": [
                   {
                       "Subnet": "192.168.100.1/24"
                   }
               ]
           },
           "Internal": false,
           "Containers": {
               "7f2fd160b8f7340d75861c1c0f743820ee713b13738a1f09252b0b17da58f111": {
                   "Name": "mycontainer",
                   "EndpointID": "44af06571b1c6334001cbb13c15702640d93930e30f415052e684a96b0d0a893",
                   "MacAddress": "02:42:c0:a8:c8:03",
                   "IPv4Address": "192.168.100.3/24",
                   "IPv6Address": ""
               }
           },
           "Options": {
               "parent": "eth0"
           },
           "Labels": {}
       }
   ]

I notice that the interface name in the docker container is 'eth0@if2' which is curious.

If I attempt to add the original ip manually:

/ # ip a a 192.168.100.2/24 dev eth0
ip: RTNETLINK answers: Operation not permitted

I have tested this on Docker version 1.12.1, build 23cf638 on Ubuntu 16.10 and Docker version 17.03.0-ce, build 60ccb22 on Ubuntu 16.04

How do I correctly add additional IPs (on the same or an additional virtual interface) in the same docker macvlan network to the same docker container?

Contributor guide

No contributing guide indexed for this repository

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 by reproducing the macvlan setup with docker network create, docker create, docker network connect, and docker start, then inspect the container interface and docker network inspect output. Trace the macvlan handling for repeated connections to the same container and verify whether both requested IP addresses are retained, or identify and document the supported limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go, linux
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.