Understanding Docker Volumes with an example

Bhargav Bachina
Bachina Labs
Published in
5 min readFeb 21, 2019

--

Before going deep into volumes, Let’s understand how containers persist data in the host filesystem.

If we look at the above diagram, whenever running container wants to persist data, it actually put that data into the writable layer through storage driver. well, we have some problems with that!!!

What are the problems

  • Data is no longer persisted and difficult to access if container stops as shown in the following diagram
  • As we can see writable layer is tightly coupled with host filesystem and difficult to move the data.
  • We have an extra layer of abstraction with a storage driver which reduces the performance.

Let’s see in action

Let’s pull the latest nginx image from the docker hub and run the container and load the home page which listens on port 80.

// pull the nginx image
docker pull nginx
// run the container
docker run -it --name=webApp -d -p 80:80 nginx

--

--