Change MTU value in Docker

Possible fix when you cannot connect to the internet from your Docker container.


August 1, 2022

If you ever run into problems, where you cannot connect to the internet from your Docker container, one reason might be incorrectly set MTU value between the host and Docker. On my host, the MTU value is set to 1462, but Docker uses 1500 by default.

Start by editing docker.service.

sudo nano /lib/systemd/system/docker.service

Change the following line,

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

by adding --mtu=1462.

ExecStart=/usr/bin/dockerd --mtu=1462 -H fd:// --containerd=/run/containerd/containerd.sock

Save the file, and restart Docker.

sudo systemctl daemon-reload
sudo systemctl start docker
sudo systemctl restart docker

At this point, if you have existing networks in Docker, they are still using the default 1500 value. You have to re-create your networks, but this time, specifying the MTU value like so.

docker network create <NAME OF NETWORK> --opt com.docker.network.driver.mtu=1462