Introduce config option for default generic network options of newly created networks#43197
Introduce config option for default generic network options of newly created networks#43197thaJeztah merged 1 commit intomoby:masterfrom dajudge:default-bridge-mtu
Conversation
|
@dajudge can you squash this to single commit and rebase with master branch? I did quick testing with this and it looks to be effective for all new networks, including ingress and all custom overlay networks as long it is set to manager node which means that it would help also with this case moby/libnetwork#2661 Will do testing with Windows also after rebase is done (now I was not able to build on Windows). @thaJeztah @cpuguy83 is this something which can be considered to be included to Moby and maybe also backported to 22.06 ? It is kind of breaking change but because most of the environments are anyway using only default MTU and those who changes it will do it on purpose it would make sense to simplify their life with this. |
|
Hi @olljanat - thanks for your feedback! If the potentially breaking nature of the patch is a problem it'd also be possible to introduce a new cmdline arg instead of reusing I'll gladly take care of rebasing in the next few days if that helps getting this PR merged! 👍 |
@olljanat done 👍 |
|
I'd love to get some feedback on this PR from you folks (@olljanat, @cpuguy83, @thaJeztah) to learn what could help bringing it forward. Do you maybe have some ideas regarding tests that could be added? What do you think about the overall concept of introducing a new cmdline flag for this? I can also help backporting if it is considered valuable to have it in 22.06 as @olljanat suggested. Your input is greatly appreciated! |
|
@dajudge purpose of tests is proof that feature works as expected and more importantly make sure that it does not go broken as part of future code changes. Because there have been already that earlier MTU setting there most probably is some tests which can be extended or alternatively you can write new one(s). Looks folder |
|
New flag seems ok to me. Just need a test and I think we can move forward. |
|
Added test case to verify behavior in the following cases:
Each case is verified by creating a new network, starting a container attached to that network and then checking the MTU of the eth0 interface in the container. |
|
Not to be annoying but is there any plans of integrating this feature yet? Id love to use it! |
|
Resolved some merge conflicts. |
|
uuuuhm |
cpuguy83
left a comment
There was a problem hiding this comment.
This seems ok, though I'd expect that such a default would be fairly driver specific.
|
Thanks for your feedback, @cpuguy83! Please let me know if there's something I can do to help move this forward! |
|
+1 on this. On our cloud provider when using Ubuntu 22.04 something has changed that caused the default mtu to break overlay networks. For now we can live with setting the mtu in our stack files but a default would help newcomers. |
|
in my setup i have to put networks:
default:
driver_opts:
com.docker.network.driver.mtu: 1420into every single service im hosting. can we please have this feature merged? |
|
Thinking about this a little bit:
This is said with the assumption that drivers are responsible for setting MTU and not libnetwork... I haven't taken the time to dig into the code and am currently on PTO. |
|
So yes, as suspected this should all be handled by the driver so we either need to namespace the options for each driver or pass down an option to drivers for max MTU. Max MTU is of course a pretty big change since every driver would need to be changed to support it. |
|
Hi @cpuguy83, many thanks for your input! Disclaimer: I'm far from being an expert on the nitty gritty networking layer details that are involved here, so please bear with me if this idea would not work for some reason I'm not taking into account. What about leaving the parameter as-is but taking a driver-specific overhead into account before applying it via My thinking here is: Line 669 in eaa7b49 driverapi.Capability struct to also include a driver-specific value for network overhead. If such a constant value could be determined for every driver then one could simply subtract that value from c.cfg.DefaultMTU before setting it as the DriverMTU, e.g. as such:
WDYT? Would it make sense to go down such a road? |
|
The drivers are responsible for setting MTU. And the only drivers today which do so are bridge and overlay. I much prefer the idea of introducing a new "Max MTU" option for drivers to subtract their overhead from over the capability idea. The packet overhead might not necessarily be a per-driver constant: per-network options could influence the overhead, for instance. As for this PR, I have to wonder whether we should be adding a special case daemon config option just for one particular network config option. What about {
"default-network-opts": {
"*": {"com.docker.network.container_iface_prefix": "foo-"},
"overlay": {"com.docker.network.driver.mtu": "1420"},
"bridge": {"com.docker.network.driver.mtu": "1450"}
}
} |
|
Is there any provision for using this option through |
|
@richardg867 what version of docker are you running? |
|
@richardg867 the |
|
Good call; also just realized we need to update the docs in https://github.com/docker/cli/blob/master/docs/reference/commandline/dockerd.md |
24.0.0-beta.1
After correcting the name, it now works for bridge networks, but overlay networks cause an unknown option error... ...even though they do work if I specify the option on the dockerd command line instead of |
|
Just found another interesting issue: default options are not applied to networks created in swarm mode through the command line. They are applied to the ingress network on swarm init (EDIT:) and any networks created through docker stack deploy, though. |
|
@richardg867 try inspecting the network while a container is attached to it. |
|
Thanks very much for this patch - we use OpenStack so it's very useful. Question: can it be expressed as a daemon.json config? I tried, but whilst this works:
This is accepted as valid syntax in daemon.json, but does not change the MTU (stays at default 1500 on creating user bridges): Yes, I can patch a config change into systemd for the docker service, but it would be nice if all I have is an error in my daemon.json which I could fix :) Many thanks, Tim |
|
If the bridge already exists it doesn't change anything. |
Hi, Thanks for taking the time to reply - I already did that. I've tried it both ways: When I put --default-network-opt=bridge=com.docker.network.driver.mtu=1442 into the systemd docker.service file, reload systemd and restart docker, bringing up containers does the right thing - new bridges are configured with MTU 1442. When I remove that option from systemd, reload systemd, add the json config above into /etc/docker/daemon.json and restart docker: The daemon restarts without error (which it doesn't do if I make a typo in that particular bit of the config) - But it seems to ignore the setting. I assumed that all dockerd command line options will map to daemon.json settings?
|
|
OK - Got it! There is a disparity in the daemon.json and the command line options: This works:
Notice the extra s on -opts. I found this out with a dive into the source code: config.go: and config_linux_test.go: It's working (not using the expected config, but working as I wanted). |
|
The plural has always been how these types of options (that can be specified multiple times on the command line) have worked; cc @dvdksn to see if we can call this out louder for the daemon.json docs. |
Maybe it's me, but I really struggled finding good daemon.json docs and examples. It was actually the example in the config_linux_test.go that alerted me. |
|
Looks like docs were added in this PR; (published at https://docs.docker.com/reference/cli/dockerd/#default-network-options) so removing the |
- What I did
I introduced a new command line parameter
--default-network-optto configure defaults for generic options for newly created networks (e.g. MTU).For example you could configure the MTU for newly created bridge networks by using the following command line:
Precendence rules:
- How I did it
--default-network-opts. Its values are stored in a newly createdDefaultNetworkOptsin the structNetworkConfigfound in the filesrc/github.com/docker/docker/daemon/config/config.gocreateNetwork()insrc/github.com/docker/docker/daemon/network.gopicks up the values fromNetworkConfig.DefaultNetworkOptsand adds them to the network options provided when creating a new network based on the type of the created network.- How to verify it
dockerd --default-network-opt=bridge=com.docker.network.driver.mtu=1234(or justdockerdwithout this PR)docker network create mynetdocker run --rm --net mynet -it ubuntu cat /sys/class/net/eth0/mtu- Description for the changelog
Introduce the
--default-network-optconfiguration option for newly created networks.