Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Docker

Docker: Fix a Container’s DNS Resolving a Name It Already Left

- 25.11.26 - ErcanOPAK

🐳 Docker: Fix a Container’s DNS Resolving a Name It Already Left

Docker’s embedded DNS resolver at 127.0.0.11 serves service-name lookups inside a container, but most application runtimes cache a resolved IP address for the life of the process rather than re-resolving on every connection — after a docker network disconnect/connect changes which network a container actually belongs to, the running process inside it can keep using an address it resolved before the change, even though docker network inspect correctly shows the container’s new, updated network membership.

🔎 The Problem

$ docker network inspect app-net --format '{{.Containers}}'
(api container no longer listed - correctly disconnected)

Inside the api container's process (already running, never restarted):
  still connecting to cached IP 172.19.0.5 for 'db'
  -> that address now belongs to a different container on the old network
  -> connection refused / wrong service responds, looks like 'db' is down

✅ Fix: Treat a Network Change as a Reason to Recreate, Not Just Reconnect

  • Treat disconnect/connect on a running container as something that needs a DNS-cache-aware restart of the process inside it, not just a network-level change — most app runtimes cache a resolved IP for the life of the process.
  • Resolve the name manually from inside the container immediately after a network change to confirm what it actually returns, rather than assuming the application layer will notice on its own.
  • When possible, recreate the container instead of hot-reconnecting its networks, so the one new container that starts gets a fresh resolver state from the beginning.

🚨 Why This Is Dangerous

  • A connection that silently keeps going to the right hostname but the wrong actual address after a network topology change can fail in ways that look like the remote service is down, when the real problem is the resolving container’s own stale state.

docker network inspect tells you the truth about right now — it says nothing about what a process already running inside that container cached ten minutes ago.

— DevOps Engineer

Related posts:

Step-by-Step: Dockerizing Existing Applications

Step-by-Step: Dockerizing Existing Applications

Docker Containers Work Locally but Fail in CI

Docker Containers Work Locally but Fail in CI

Docker: Fix a Healthcheck That Reports unhealthy Forever Because Its Exec Form Command Needs a Shell...

Docker: Fix a Healthcheck That Reports unhealthy Forever Because Its Exec Form Command Needs a Shell...

Views: 15
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Photoshop: Fix a Layer Mask Inverting After a Cross-Document Copy
C#: Fix a Custom Awaiter Resuming on the Wrong Thread Context

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 868 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com