RSS

Modifying default MTU for docker-containers

28 Feb

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)

 
3 Comments

Posted by on February 28, 2016 in Docker, Linux, Networking

 

3 responses to “Modifying default MTU for docker-containers

  1. 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.

     
  2. guilherme lucas

    November 26, 2016 at 7:45 pm

    you saved my life! thanks a lot!

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
<span>%d</span> bloggers like this: