Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungBreeze TTS 2 vs ElevenLabs: Open Source TTS Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungAgentic AI vs Generative AI: The 2026 Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungI made my agent prove every quote against the source document(23.09.2026 um 05:45 Uhr)
Sichere Programmierung8mb.video Alternative: Skip the Line, Skip the Upsell(23.09.2026 um 05:47 Uhr)
Sichere ProgrammierungBuilding a GTA 6 JSON API for entities and current status(23.09.2026 um 05:52 Uhr)
Sichere ProgrammierungEvery filter needs a documented exception(23.09.2026 um 06:01 Uhr)
Sichere ProgrammierungBreeze TTS 2 vs ElevenLabs: Open Source TTS Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungAgentic AI vs Generative AI: The 2026 Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungI made my agent prove every quote against the source document(23.09.2026 um 05:45 Uhr)
Sichere Programmierung8mb.video Alternative: Skip the Line, Skip the Upsell(23.09.2026 um 05:47 Uhr)
Sichere ProgrammierungBuilding a GTA 6 JSON API for entities and current status(23.09.2026 um 05:52 Uhr)
Sichere ProgrammierungEvery filter needs a documented exception(23.09.2026 um 06:01 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Building Docker Containers with Persistent Storage

One of the first surprises new Docker users encounter is that data disappears when a container is removed. Imagine deploying a web application or a database inside a Docker container. Everything works perfectly until the container crashes…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

One of the first surprises new Docker users encounter is that data disappears when a container is removed.



Imagine deploying a web application or a database inside a Docker container. Everything works perfectly until the container crashes or you redeploy your application. Suddenly, all your uploaded files, logs, or database records are gone.



Why?



Because containers are ephemeral by design. They are designed to be created, destroyed, and recreated quickly. Unless data is stored outside the container, it disappears together with the container.



In this article, you'll learn the three common ways Docker handles storage and when each one should be used.









Understanding Docker Storage



There are three common ways to work with data in Docker:




























Storage Type Persists After Container Removal? Managed By
Container Writable Layer ❌ No Docker
Bind Mount ✅ Yes Host Machine
Docker Volume ✅ Yes Docker


Let's explore each one with practical examples.









1. Container Writable Layer (Ephemeral Storage)



By default, every Docker container has a writable layer where files can be created or modified while the container is running.



Think of it like a teacher writing notes on a whiteboard during a class. Once the class ends and the board is cleaned, everything written on it is gone.



Similarly, when a container is removed, everything stored inside its writable layer is lost.






Step 1: Start a container






docker run -it --name notes alpine sh






Inside the container:




echo "My first note" > notes.txt
cat notes.txt






Exit the container:




exit






Remove it:




docker rm notes






Create a new container:




docker run -it --name notes alpine sh






Try reading the file again:




cat notes.txt









Observation



The file no longer exists because it was stored only inside the container.






When is this useful?




  • Temporary files

  • Cache

  • Generated reports

  • Session data









2. Bind Mount



A bind mount connects a folder on your host machine directly into a container.



Think of it as giving someone access to a folder on your computer. They can read from it and write to it, and you can immediately see the changes from your host machine.



Unlike the container's writable layer, the data remains on your computer even after the container is deleted.






Create a folder






mkdir docker-notes






Run the container:




docker run -it \
--name bind-demo \
-v $(pwd)/docker-notes:/app/data \
alpine sh






Inside the container:




echo "Bind Mount Note" > /app/data/notes.txt






Exit:




exit






Verify the file on your host machine:




cat docker-notes/notes.txt






Remove the container:




docker rm bind-demo






Check the file again:




cat docker-notes/notes.txt









Observation



The file is still available because it is stored on the host machine, not inside the container.






Common Use Cases




  • Local development

  • Editing source code

  • Sharing files between host and container









3. Docker Volumes



Docker volumes are the recommended way to persist data in production.



Unlike bind mounts, Docker manages the storage location for you.



Think of a Docker volume as a portable external drive that Docker can attach to any container whenever it starts.



This is the preferred method for storing application and database data.






Create a volume






docker volume create notes-volume






Run a container using the volume:




docker run -it \
--name volume-demo \
-v notes-volume:/app/data \
alpine sh






The option




-v notes-volume:/app/data






attaches the Docker volume to the container.



Inside the container:




echo "Volume Note" > /app/data/notes.txt






Exit:




exit






Remove the container:




docker rm volume-demo






Start another container using the same volume:




docker run -it \
--name volume-demo2 \
-v notes-volume:/app/data \
alpine sh






Check the file:




cat /app/data/notes.txt









Observation



The file still exists because it was stored inside the Docker volume instead of the container.






Common Use Cases




  • Databases

  • Production applications

  • User uploads

  • Application logs









Comparison












































Feature Writable Layer Bind Mount Docker Volume
Persists after container removal
Stored on host
Managed by Docker
Best for Production ⚠️ Sometimes
Best for Development








Which One Should You Use?



Choose the storage option that matches your use case:





  • Container Writable Layer → Temporary data that doesn't need to survive.


  • Bind Mount → Local development where you want to edit files directly on your machine.


  • Docker Volume → Databases and production workloads where persistent storage is essential.









Final Thoughts



Understanding Docker storage is one of the most important skills for anyone learning containers.



If you don't store your data correctly, removing a container can also remove everything your application has generated.



As a general rule:




  • Use the container writable layer for temporary data.

  • Use bind mounts during development.

  • Use Docker volumes in production.



Following these best practices will help you build containerized applications that are reliable, portable, and easier to maintain.









Resources



You can find the complete examples used in this article in my GitHub repository:



👉 https://github.com/highbee2810/Docker_storage_tutorials



If this article helped you, consider leaving a ❤️ and following me for more practical Docker, DevOps, and Cloud tutorials.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Building Docker Containers with Persistent Storage

Thematisch verwandte Begriffe: Building, Docker, Containers, with · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-18163 | IBM Financial Transaction Manager (FTM) for RedHat OpenShift could allow…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick