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 Volume Mount Hiding Files Baked Into the Image

- 26.11.26 - ErcanOPAK

🐳 Docker: Fix a Volume Mount Hiding Files Baked Into the Image

A bind mount or named volume mounted over a path the image already populated during its build doesn’t merge with what the image put there – it overlays the mount’s own content on top, completely replacing the container’s view of that directory regardless of what the Dockerfile’s RUN steps spent minutes building into the image. If the host side (or the volume) is empty at that path, the container doesn’t fall back to the image’s version of the directory – it just sees an empty directory, and whatever dependencies or generated files the build produced there are invisible at runtime, even though the image itself is completely intact.

🔎 The Problem

# Dockerfile: RUN npm install   (populates /app/node_modules in the image)

# docker-compose.yml:
services:
  web:
    build: .
    volumes:
      - ./app:/app   # bind mount for live code editing
      # host ./app/node_modules is empty or doesn't exist locally ->
      # it now overlays and HIDES the image's /app/node_modules entirely
    command: node server.js
# Container error: Cannot find module 'express'
# -- even though `docker build` completed npm install successfully

✅ The Fix

  • Declare the subdirectory that must keep the image’s build output as its own separate volume (for example a named volume mounted specifically at /app/node_modules) so that nested path keeps the image’s content instead of being blanked out by the broader bind mount covering /app.
  • In Compose, verify the EFFECTIVE mount list with docker compose config (or docker inspect on the running container) rather than assuming the compose file’s intent is what actually took effect – a more general mount can silently take priority over what you expected a nested one to protect.
  • When a ‘missing dependency’ error only happens under the dev compose setup and not in a plain docker build or in CI, check the container’s actual mounts first – the image is very likely fine, and the mount is the only thing hiding its content.

🚨 Why This Is Dangerous

Because the exact same image runs perfectly in CI or production (where no development bind mount exists to hide anything), this looks exactly like a ‘works everywhere except my machine’ environment difference, sending time toward comparing environments when the real cause is a single mount path overlapping a directory the image already built.

A volume mount doesn’t ask what’s already there before it takes over – it replaces it, even when what’s already there took your build five minutes to produce.

— DevOps Engineer

Related posts:

Docker: Fix a Stale COPY Layer After Editing .dockerignore

Docker: Fix a Stale COPY Layer After Editing .dockerignore

Docker: Clean Up Disk Space by Removing Unused Images and Containers

Docker: Clean Up Disk Space by Removing Unused Images and Containers

Docker Container Works Once, Then Fails

Docker Container Works Once, Then Fails

Views: 8
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

C#: Fix a Span Capture Throwing in an Async Local Function
C#: Fix a Record Struct Losing Equality After Adding a Field

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 @ 629 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 561 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