The Wayback Machine - https://web.archive.org/web/20240927194234/https://www.geeksforgeeks.org/data-storage-in-docker/
Open In App

Data Storage in Docker

Last Updated : 30 Mar, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Docker images are built-in form of layers and docker containers store all the data being used, on the container writable layer which is only persisted till the lifespan of the container i.e. it is no longer accessible once the container is removed. This also makes it difficult to get the data out of the container if it is required by some other processes.

To persist the data irrespective of the container’s lifecycle so that the files are available in the host filesystem even if the container is no longer available, Docker provides two options:

  1. Docker volumes
  2. Bind mounts

Though we can also use tmpfs mount if you’re using Docker on Linux and named pipes if using Docker on Windows.

In this article, we’ll be covering the docker volumes and bind mounts with their differences in terms of use cases and effectiveness.

1. Docker Volume

Volumes are the directories or files that exist on the host filesystem and are mounted to the containers for persisting data generated or modified by them. They are stored in the part of the host filesystem managed specifically by Docker and it should not be modified by non-Docker processes. Volumes are the most preferred way to store container data as they provide efficient performance and are isolated from the other functionalities of the Docker host.

We can use the following command to create docker volume -:

docker volume create <volume_name>

We can mount a volume to multiple containers simultaneously and Docker doesn’t remove them even if they’re not being used by any running container. To remove a volume, we can use the following command -:

docker volume prune

In a Linux filesystem, we can find the available volumes at the following path ‘/var/lib/docker/volumes/ ‘, while in Windows, we can get the location of the volume by running the following command in file explorer -:

\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes

To learn more about volumes and how to mount them to a container click here.

Commands to create volume

2.) Bind Mounts

This is also a mechanism provided by Docker to store container data on localhost, but the directory or file mounted using bind mounts can be accessed by non-Docker processes as well and it relies on the host machine’s filesystem having a specific directory structure available because it uses absolute path for binding.

Bind mounts have limited functionality and can’t be managed directly through Docker CLI, thus making it less preferable in comparison to volumes. Moreover, it allows the container to modify the host filesystem i.e. it can create, modify or delete important file directories which can impact security and non-Docker processes as well.

3.) tmpfs mounts

When using Docker in Linux, you can also create storage volume for containers using tmpfs mount. But contrary to bind mounts and volumes, this type of mount is temporary and persists on host memory.

Once the container is stopped, the tmpfs mount is removed and files stored using it won’t be available anymore. This type of mount has very limited use and can only be used by Linux users. Moreover, it does not allow sharing of mounted data among containers.

4.)  Named pipes

When to use Volumes 

Following are some potential use cases for volumes -:

  • Volumes can be used to share data among multiple containers in a secure manner without affecting the host filesystem.
  • They provide convenient backup and data migration from one Docker host to another.
  • We can easily manage volumes using Docker CLI and Docker APIs, which is a limitation in terms of bind mounts.
  • The insignificance of host filesystem structure provides decoupling of Docker host configuration from container runtime.
  • It provides volume drivers which help in storing data to remote hosts or cloud providers.
  • Volumes are stored in Linux VM thus providing lower latency and higher throughput. They are highly performant on the Docker desktop, thus making them a better choice for write-intensive applications like data storage.

When to use Bind Mounts

Despite limited functionalities, we can use bind mounts in the following cases -:

  • It can be used to provide shared configuration files between host and container. Ex- Docker mounts ‘/etc/resolv.conf ‘  to containers for DNS resolution.
  • In case the host file system is guaranteed to remain consistent and the mounted volume is not accessed by non-Docker processes, we can use bind mounts for storing data.

Previous Article
Next Article

Similar Reads

Docker Storage Solutions Beyond Volumes and Bind Mounts
Docker is a platform that helps developers create, distribute, and operate container programs. Volumes and bind mounts are the two ways in which files may be persistently stored on the host computer by Docker containers. Moreover, Docker allows containers to keep files in the memory of the host computer. What are Docker Volumes?Docker Volumes are w
5 min read
How to Use Docker For Fault Tolerance with Docker Replicas?
Docker is a set of platform-as-a-service products that use OS-level virtualization to deliver software in packages called containers. A cluster of docker engines is called a swarm. Docker Swarm is a cluster management and orchestration feature embedded in the Docker Engine. Docker ReplicasDocker replicas refer to running multiple instances of a doc
4 min read
How to Use Docker For Cross-Platform Containerization with Docker Buildx?
Docker has completely modified the manner in which software program is evolved and deployed, with the aid of introducing containerization generation. In order to package programs with their dependencies and make certain consistency of conduct across many contexts, packing containers offer a compact and portable solution. Deploying containerized app
7 min read
Docker Compose vs Docker Swarm
Docker is one of the most widely used container-based software on the market. Docker is an open-source platform for creating, deploying, and managing containerized applications. Docker allows us to simply bundle our apps into containers and can be deployable on any platform that supports docker software acting as a platform independent. What Is Doc
6 min read
Docker CLI vs Docker Desktop
Docker is an open-source platform. It is used to containerize applications. This is done by packaging applications along with their dependencies into containers that can be easily deployed. Users interact with Docker primarily using either the Docker CLI or the Docker Desktop Application. In this article, we'll be looking into each one in detail an
5 min read
Docker: How To Use Bash With An Alpine Based Docker Image?
Docker is a tool that is used to encapsulate the application with all its dependencies, called Docker containers. On the other hand, Alpine Linux is a lightweight and minimal Linux distribution. Here in this guide, I will first discuss what Docker is. Then I will discuss what Alpine is. After this, I will walk you through the different steps to ins
5 min read
Docker - Deploying WebApps on Docker
Docker applies abstraction at the software layer of the operating system to create an instant and portable environment that includes everything you need: a Linux kernel, libraries, system tools like grep or sshfs, plus applications (web servers/services) and all dependencies needed by those applications (e.g., database engines). When deployed, thes
9 min read
How To Use Docker Security Tools To Secure Docker Container Images
Docker is a tool that is used to package the application and its dependencies into compact units called Docker containers. In this guide, I will first discuss what a docker is. Then I will discuss a security tool called Trivy, which is used to scan and detect Docker image vulnerabilities. After this, I will walk you through the different steps to d
11 min read
Docker - Publishing Images to Docker Hub
Docker is a container platform that facilitates creating and managing containers. In this article, we will see how docker stores the docker images in some popular registries like Dockerhub and how to publish the Docker images to Docker Hub. By publishing the images to the docker hub and making it public it gives users more flexibility in creating e
8 min read
Docker - Using Public Repositories To Host Docker Images
Docker is a software platform for creating isolated virtualized environments for building, deploying, and testing applications with ease. In this tutorial, we will learn how to host public repositories on docker hub which is a hosted repository service provided by Docker for finding and sharing container images. Just like GitHub allows the hosting
10 min read
Docker - Docker Container for Node.js
Node.js is an open-source, asynchronous event-driven JavaScript runtime that is used to run JavaScript applications. It is widely used for traditional websites and as API servers. At the same time, a Docker container is an isolated, deployable unit that packages an application along with its dependencies, making it highly scalable and maintainable.
12 min read
Getting started with Spring Boot 3, Kafka over docker with docker-compose.yaml
We will create two Spring Boot 3.x applications (Producer and Consumer) requiring Java 17 to get started. We need a queuing service to pass messages from the producer Spring service to the consumer Spring service. Here, we will use Kafka. Confluent provides Docker images that are easy to use for setting up the Kafka environment. Since we will use a
5 min read
Docker Logs Inside the Docker Container
While running containers, it is important to know about various information like running processes generated by the container. Docker logs allow us to get this information regarding the containers. While it's pretty straighforward to check logs directly from Docker CLI, here we will see how to check logs from within a container. What is Docker?Dock
5 min read
Docker Tips : about /var/run/docker.sock
Docker has thus gained lots of usage today in software development. It allows developers to create, deploy, and run their applications in isolated environments. Such isolation will guarantee consistency between development, testing, and production environments and, finally, app security and scalability. A central part of the functionalities of Dock
8 min read
How To Use Docker Desktop To Deploy Docker Containerized Applications
Docker Desktop is an user-friendly tool that simplifies the deployment of Docker containerized applications on your local machine. It provides a graphical interface for managing containers, images, and volumes, making it accessible for developers and DevOps professionals. In this guide, we will walk you through the essential steps of using Docker D
9 min read
Docker Start vs Docker Run
Docker is a platform as a service(PaaS) that allows engineers to use OS-level virtualization to automate the deployment of applications inside lightweight and portable packages called containers. The containers have a very big advantage as they allow apps to run on different platforms effortlessly, and reduce the old headache of "it runs on my mach
7 min read
Docker for Data Science
Data Science includes a large amount of data that performs computations and deploys models. With the deployment of the models and the development of the software the performance and the maintenance of the consistent environment may vary. So, for this Docker, an open-source platform is being introduced. It provides containers that are an excellent s
9 min read
How to Use Docker For Big Data Processing?
Docker has revolutionized the way software program packages are developed, deployed, and managed. Its lightweight and transportable nature makes it a tremendous choice for various use instances and huge file processing. In this blog, we can discover how Docker may be leveraged to streamline huge record-processing workflows, beautify scalability, an
13 min read
Docker Data Volume vs Mounted Host Directory
Docker can be defined as an open-source tool that allows the software to be deployed within containers which are basic, yet extremely efficient and flexible entities on the system level, and how this tool has transformed the process. Some of the significant aspects that help make Docker so powerful are data volumes and the mounted host directories.
10 min read
Docker Compose Volumes for Container Data
For modern application development, data persistence is one of the most important aspects of containerized applications. One way to achieve this need for robustness when using Docker volumes is by using Docker Compose, a tool that makes orchestrating multi-container Docker applications easier. Volumes are a key feature of Docker that allows you to
7 min read
Configure a Pod to Use a PersistentVolume for Storage
Using a PersistentVolume with a Pod in Kubernetes ensures that data stored by the Pod persists beyond the Pod's lifecycle. This is crucial for applications that require durable storage, such as databases or file servers, as it prevents data loss when Pods are restarted, rescheduled, or scaled up/down. PersistentVolumes provides a reliable way to ma
5 min read
How to manage storage with Podman volumes
Podman(Pod Manager) is the Daemonless, Open Source, Linux Native utility to create, manage, and run OCI(Open Container Initiative) containers and pods. Podman is a great Docker container alternative when you need greater security, UID separation via namespaces, and system integration. Podman is excellent for development, testing in CI/CD pipelines,
4 min read
How to Link Multiple Container in Docker ?
Docker is a free software created by Docker Inc. and it enables clients to create free and confined environments where the users can deploy their applications. A container is a standard unit of software that packages up code and all its dependencies from one computing environment and runs it quickly and reliably into another computing environment.
2 min read
Installing Helm & Kubernetes in Docker
Helm is simply a package manager for Kubernetes. It helps you manage Kubernetes applications — Helm Charts helps you define, install, and upgrade even the most complex Kubernetes application. Implementation: Follow the below steps to install Helm and Kubernetes in Docker: Step 1: Installing Docker First, download the Docker.exe from the official si
2 min read
Docker - Containers & Shells
Docker is a set of platforms as a service (PaaS) products that use Operating system-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels. All containers are
5 min read
Docker - Setup in RHEL8 for Python
Developing an application or software requires starting several microservices in one machine. So if you are 10 of those services then you require 10 VMs on that machine. How Docker solves the above problem? With help of docker, you can run multiple microservices in the same VM by running multiple docker containers for each microservices. Containers
2 min read
Docker Networking
Pre-requisite: Docker Docker Networking allows you to create a Network of Docker Containers managed by a master node called the manager. Containers inside the Docker Network can talk to each other by sharing packets of information. In this article, we will discuss some basic commands that would help you get started with Docker Networking. Docker Ne
5 min read
How To Use Docker for Machine Learning?
Docker is a containerization platform that allows you to package your machine learning code and dependencies into an image that can be run on any machine. Docker allows your application to be separated from your infrastructure. The image that you created is portable, so you can run it on any machine that has Docker installed. Docker for MLWe are go
5 min read
Difference Between Docker and Virtualization
Years back when organizations were planning to transform their projects with emerging technologies like Cloud or On-Premises Server, they came up with two solutions i.e. Docker and Virtual Machines. Both of them were introduced to solve these organizational issues using Containers. They simplify the deployment process of applications and microservi
7 min read
Docker - Installation on Windows
In this article, we are going to see how to install Docker on Windows. On windows if you are not using operating system Windows 10 Pro then you will have to install our docker toolbox and here docker will be running inside a virtual machine and then we will interact with docker with a docker client To understand this let us look at the left side of
2 min read
Article Tags :