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
<tuncated>
ExecStart=/usr/bin/docker daemon -H fd:// –mtu=1450
<truncated>
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
collisions:0 txqueuelen:0
RX bytes:508 (508.0 B) TX bytes:508 (508.0 B)
Jóhann Geir Jónsson
September 28, 2016 at 12:11 pm
Better yet, create this file: /etc/systemd/system/docker.service.d/set_mtu.conf
with the following content:
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// –mtu=1450
That way, you only override the relevant part of the systemd service file for docker, not the whole file. Note that the double ‘ExecStart=’ is intentional. The first line clears the value. Otherwise, systemd would complain about double ExecStart entries, one in the set_mtu.conf file and the other one in the /lib/systemd/system/docker.service file.
Rahul
September 29, 2016 at 6:51 am
You can also modify /etc/default/docker in ubuntu and specify $DOCKER_OPTS flag in docker.service file. More details on how to do this can also be found at this link: http://docs.openstack.org/developer/kolla/multinode.html
guilherme lucas
November 26, 2016 at 7:45 pm
you saved my life! thanks a lot!