Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

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

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Docker

Docker: Fix a Named Volume That Keeps Showing Old Data After a Rebuild Because Docker Only Seeds It Once, the First Time It’s Created

- 10.10.26 - ErcanOPAK

🐳 The Volume That Stopped Listening to the Image

When a Dockerfile declares a VOLUME at some path, Docker populates that path from the image’s own baked-in content, but only the very first time a volume mounted there is genuinely empty – after that initial population, whatever data already lives in the named volume always takes priority over anything newer baked into a later image rebuild. A team that rebuilds the image with fresh seed data, expecting docker-compose up to pick it up through the same named volume, instead keeps seeing the original data from months ago, because the volume was already populated once and Docker has no mechanism to refresh it from a newer image automatically.

🔎 The Problem

# Dockerfile
FROM postgres:16
COPY ./seed-data /seed
VOLUME /var/lib/postgresql/data

# docker-compose.yml
services:
  db:
    build: .
    volumes:
      - db-data:/var/lib/postgresql/data
volumes:
  db-data:

# First run: db-data is empty, so Docker populates it from the
# freshly built image's content - works exactly as expected.
$ docker compose up -d

# Months later: seed data is updated, image is rebuilt...
$ docker compose build
$ docker compose up -d
# ...but db-data already has content from the FIRST run. Docker
# only seeds a volume once, when it's empty - the rebuilt image's
# newer seed data is never copied in, with no warning that this
# is what happened.

✅ Fix: Decide Deliberately When a Volume Should Reset

  • Remove the named volume explicitly – docker volume rm, or docker compose down -v – whenever a rebuild is genuinely meant to refresh seed data, rather than assuming a rebuild alone will update an already-populated volume.
  • Separate persistent application data from seed or reference data that should always come from the image, keeping the latter in a bind mount or baked directly into the image rather than a named volume that only gets seeded once.
  • Document explicitly, wherever the Dockerfile’s VOLUME instruction is used for seeding, that it only takes effect the first time the volume is created – so a teammate rebuilding months later doesn’t assume an update to seed data will automatically show up.

⚠️ Why This Is Easy to Miss

  • The first time anyone sets this up, everything works exactly as expected – the volume is empty, Docker seeds it from the image, and there’s no reason yet to suspect that behavior won’t repeat on the next rebuild.
  • A rebuild appears to succeed completely – the build logs show the new seed data being copied into the image without any error – so there’s nothing in the build process itself suggesting the running container’s actual volume won’t reflect any of it.

A Docker volume gets seeded from the image exactly once – after that, the volume’s own data always wins, no matter how many times you rebuild the image underneath it.

— DevOps Engineer

Related posts:

Docker Networks: Master Container Communication for Microservices

Docker Networks: Master Container Communication for Microservices

Docker: Fix a Bind Mount on Windows That Silently Breaks File-Change Notifications Inside a Linux Co...

Docker: Fix a Bind Mount on Windows That Silently Breaks File-Change Notifications Inside a Linux Co...

Docker: Fix a Build ARG That Silently Resolves Empty in a Later Stage Because ARG Scope Doesn't Carr...

Docker: Fix a Build ARG That Silently Resolves Empty in a Later Stage Because ARG Scope Doesn't Carr...

Views: 8

Post navigation

ASP.NET Core: Fix a Custom Model Binder That Never Runs Because a Built-In Binder Already Matched the Same Property Type First
C#: Fix a ConditionalWeakTable Entry That Disappears Because Nothing Else Keeps Its Key Alive

Leave a Reply Cancel reply

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

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

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