Recently, I had a requirement to configure docker-containers to use MTU lesser than 1500. I was running containers on a cloud-instance where the default MTU was set to 1450. Due to this, the containers were not able to download packages when the packet-size exceeded 1450. Following steps helped me to resolve this issue. These steps are tested on Ubuntu 15.10, but should also work for other platforms/versions.
1. Copy /lib/systemd/system/docker.service to /etc/systemd/system/docker.service. This is a good practice than modifying the original file itself.
$ cp /lib/systemd/system/docker.service /etc/systemd/system/docker.service
2. Modify the copied file and specify “–mtu=1450”. Note that we have two ‘-‘ before mtu:
$ vi /etc/systemd/system/docker.service
ExecStart=/usr/bin/docker daemon -H fd:// –mtu=1450
3. Reload the daemon and restart docker. Make sure to restart docker after you do daemon-reload.
$ sudo systemctl daemon-reload
$ sudo service docker restart
Now your containers would be getting MTU as 1450 for their ethernet adapters.
$ docker run -it ubuntu /bin/bash
root@686f366a0d52:/# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02
inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1450 Metric:1
RX packets:6 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:508 (508.0 B) TX bytes:508 (508.0 B)