moby: Networking between containers in custom network breaks after time

Description

Containers will be able to communicate, but at some point I start getting “no route to host” seemingly randomly.

Sometimes this will resolve itself, but most of the time I have to redeploy the containers or restart the system.

Reproduce

  1. docker-compose up -d
version: '3.7'

services:
  nginx:
    restart: unless-stopped
    build: ../nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - static_files:/var/www/html

  django:
    restart: unless-stopped
    build: ../django
    env_file:
      - .env
    volumes:
      - static_files:/static
    ports:
      - "8000:8000"
    depends_on:
      - crate
      - redis

  redis:
    restart: unless-stopped
    image: redis:7.2.4
    ports:
      - "6379:6379"
    command: redis-server --save "" --appendonly no

  crate:
    restart: unless-stopped
    image: crate:5.4.7
    environment:
      - CRATE_HEAP_SIZE=8192m
    ports:
      - "4200:4200"
      - "5442:5432"
    volumes:
      - crate_data:/data
    command: crate -Cnetwork.host=_site_ -Cpath.repo=/data/backup

  events:
    restart: unless-stopped
    build: ../events
    ports:
      - "8081:8081"
    env_file:
      - .env
    volumes:
      - /home/ubuntu/sql_logs:/debug

  postgres:
    image: postgres:16-bullseye
    volumes:
      - pg_data:/var/lib/postgresql/data

volumes:
  crate_data:
  static_files:
  pg_data:

Expected behavior

Network is reliable

docker version

Client: Docker Engine - Community
 Version:           25.0.1
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        29cf629
 Built:             Tue Jan 23 23:09:55 2024
 OS/Arch:           linux/arm64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          25.0.1
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       71fa3ab
  Built:            Tue Jan 23 23:09:55 2024
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.27
  GitCommit:        a1496014c916f9e62104b33d1bb5bd03b0858e59
 runc:
  Version:          1.1.11
  GitCommit:        v1.1.11-0-g4bccb38
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client: Docker Engine - Community
 Version:    25.0.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.2
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 5
  Running: 5
  Paused: 0
  Stopped: 0
 Images: 32
 Server Version: 25.0.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: a1496014c916f9e62104b33d1bb5bd03b0858e59
 runc version: v1.1.11-0-g4bccb38
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.2.0-1018-aws
 Operating System: Ubuntu 22.04.3 LTS
 OSType: linux
 Architecture: aarch64
 CPUs: 2
 Total Memory: 3.746GiB
 Name: ip-172-30-30-160
 ID: GMOE:YHEH:24T3:2O6J:XF44:XZNY:OMFP:7RQC:7ALL:7633:PJ2O:HX2Y
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional Info

This is running on Ubuntu 22.04 LTS using kernel 6.2.0-1018-aws on ARM64

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 3
  • Comments: 24 (10 by maintainers)

Most upvoted comments

Hi, We have experienced similar symptoms that might be related to the same root cause. Hope this will help to get closer to understand what happens.

Our environment: Centos 7 fully updated to latest patches. One ethernet connection on the host with a simple IPv4 address. We have multiple local scoped bridge networks. The different nets are used to communicate between containers on the host (like access to a db container), finally we publish frontend facing services to fixed ports on the host network. After the update to v25 there were connection errors to published ports from otside, randomly giving “No route to host” errors on TCP connect.

During troubleshooting I was able to reproduce the problem inside the docker host. To reproduce the problem I started to connect from the host having IP 192.168.1.1 to a local published port via telnet 192.168.1.1 8080 I was able to reproduce the problem, sometimes the connection was established normally, sometimes the there was random delay, and sometimes got the “No route to host” error. I have tested telnet localhost 8080 as well, in that case it was working reliably. The problem appeared on multiple host with many containers images and ports.

I also took a packet trace on eth0 during test connection from outside, there I saw that sometimes there were retries sent from the client and the connection proceeded later on, other times the initial SYN pack and it’s retries were unanswered for some time and after that an ICMP “Destination unreachable” was sent out of the docker host.

We have not have problems like this before the update and undoing the update fixed the problem in all cases.

Hope this helps.

Thanks for the thorough explanation here. Helps to understand why this is happening. I think when you’re using the bridge network, you can’t specify IP addresses (at least in Portainer). Gives you some error message that you can’t and the only way I’ve found to be able to specify an IP is to put it on a custom docker network, which I probably should do, but haven’t.

But, if we can get everyone on the same page and updating containers properly, then yeah would be a lot better. Right now, I’m having to go back and look after every restart or update of the server or docker or multiple containers to make sure there’s no duplicates. It’s more of an inconvenience than anything. Would like to do updates/restarts without cleaning up after lol.

Thanks again. Looking forward to these updates in Feb.

Yes @robmry I do use Portainer to manage them as well as Watchtower to update some containers automatically.

Ok, thank you, that’ll be why then …

At the moment, there’s no way for Portainer/Watchtower to tell the difference between a MAC address that was explicitly configured, and one that was generated by Docker (based on the IP address).

So, they assume it’s explicitly configured and include the current MAC address as explicit config when re-creating the container. But, they don’t explicitly configure the IP address.

Then, if the container gets a different IP address when it’s re-created (which is likely), the MAC address will still be the old one - so the MAC address is no longer derived from that container’s IP address. When the original IP address is used by a different container, it gets the original MAC address because it’s derived from the IP address, but the old container is still using it. As new containers are restarted, each will get a locked-in MAC address, and more duplicates are likely to be created.

At the moment, I think the only workaround is to explicitly configure IP addresses (and/or MAC addresses).

In moby 28.0, we’ll drop the mapping from IP to MAC addresses (https://github.com/moby/moby/pull/48808) - MAC addresses will be randomly generated. That’ll solve this problem in a roundabout way - it won’t matter if a randomly generated MAC address gets “stuck” to a container, because that MAC address won’t be reused for another container.

(At the moment it looks like 28.0 will ship in Feb, with release candidates available early in the new year.)

Separately, we should give Portainer (and the like) a way to tell the difference between configured and generated MAC addresses. That’s https://github.com/moby/moby/issues/48168.

Hi @kierankhan - as you say, it sounds like a different problem, with some similar symptoms. So, please could you raise a new issue for it? It sounds like we’ll need to dig a bit deeper to find out what’s going wrong. (Ideally, if possible, please paste in text rather than images.)

@robmry we can confirm that your description of the issue and the mitigation worked. Recreating the affected containers with 25.0.1 helped to prevent the duplicate MAC addresses

@robd003 There’re a few things that could help us better understand what’s going on:

  • Turn on debug logs as per documented here: https://docs.docker.com/config/daemon/logs/#enable-debugging, and provide any logs emitted around the time the bug starts ;
  • The output of both iptables-save and conntrack -L when this occurs ;
  • You can also try running conntrack -E to see live conntrack events, until the bug appears.
  • The output of docker network inspect where this bug happens (ie. needs to match the other item asked here), and the IP addresses of affected containers on that network.
  • And also, did you update any other software around the same time as the Engine? (eg. kernel, systemd, etc…)