Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAC address defining doesn't work #1

Closed
NiXuB86 opened this issue Sep 1, 2019 · 7 comments
Closed

MAC address defining doesn't work #1

NiXuB86 opened this issue Sep 1, 2019 · 7 comments

Comments

@NiXuB86
Copy link

NiXuB86 commented Sep 1, 2019

I tried to start container with predefined MAC address to setup static DHCP lease for container:
docker run --rm -ti --network shared-net --mac-address 66:5e:28:93:6f:60 alpine
In container MAC address defines successfully:

/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
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
112: shared-bridge0@if113: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP qlen 1000
link/ether 66:5e:28:93:6f:60 brd ff:ff:ff:ff:ff:ff
inet 192.168.28.101/24 brd 192.168.28.255 scope global shared-bridge0
valid_lft forever preferred_lft forever

But on my router it shows another MAC: 5e:f0:e1:a0:7d:17 for lease with this IP: 192.168.28.101.
I think that DHCP client that runs on host using random MAC every time.
And new random MAC is used when container created/restarts.
Or I can set static IP address, but I don't know how to do this with this docker network driver.
What I'm want to do is to connect docker container to linux bridge managed by systemd-networkd and set IP address to it. And I don't want to use pipework script for this because when host/container restarts it needs to be executed again.

@devplayer0
Copy link
Owner

Ah, looks like this is due to the fact that Docker only assigns the requested MAC address when moving the interface into the container.

@NiXuB86
Copy link
Author

NiXuB86 commented Sep 1, 2019

Can we make another flag to define MAC for DHCP client?

@devplayer0
Copy link
Owner

devplayer0 commented Sep 1, 2019

Can we make another flag to define MAC for DHCP client?

Not necessary, I've updated NetworkDriver.CreateEndpoint to manually apply the MAC address before running udhcpc (when one is supplied).

Let me know if this fixes the issue for you!

@NiXuB86
Copy link
Author

NiXuB86 commented Sep 1, 2019

Ok, thanks! I will check this in a few hours

@NiXuB86
Copy link
Author

NiXuB86 commented Sep 1, 2019

Everething is working fine, man you incredible!!! I tried to setup this for 2 weeks)

@devplayer0
Copy link
Owner

Everething is working fine, man you incredible!!! I tried to setup this for 2 weeks)

Glad it helped 😄

@meiser79
Copy link

meiser79 commented Oct 7, 2024

Hi, I cannot get it working with self-compiled docket-net-dhcp (including the fix in pull request #43).

I specified "mac_address" in the docker-compose file, but it's not used.

Any ideas how to fix it? Thanks a lot for your help!

EDIT: I found the solution here to work with a newer docker version. The MAC address is now defined in the networks section. It should look like this for docker-net-dhcp:


version: '3'
services:
  app:
    hostname: my-http
    image: nginx
    networks:
      dhcp:
        mac_address: 86:41:68:f8:85:b9
networks:
  dhcp:
    external:
      name: my-dhcp-net

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants