0% found this document useful (0 votes)
25 views

Docker Containers Volume

The document discusses different types of mounts that can be used in Docker containers including volumes, bind mounts, and tmpfs mounts. Volumes are fully managed by Docker and allow data sharing between containers. Bind mounts use host machine filesystems. Tmpfs mounts store data in host memory only and data is lost when containers stop.

Uploaded by

Ananth M.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Docker Containers Volume

The document discusses different types of mounts that can be used in Docker containers including volumes, bind mounts, and tmpfs mounts. Volumes are fully managed by Docker and allow data sharing between containers. Bind mounts use host machine filesystems. Tmpfs mounts store data in host memory only and data is lost when containers stop.

Uploaded by

Ananth M.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

The Docker File System

A docker container runs the software stack defined in an image. Images are
made of a set of read-only layers that work on a file system called the Union
File System. When we start a new container, Docker adds a read-write layer on
the top of the image layers allowing the container to run as though on a standard
Linux file system.
So, any file change inside the container creates a working copy in the read-write
layer. However, when the container is stopped or deleted, that read-write
layer is lost.
Different Mount Types for Docker Containers :

Volumes

These are the most common mount option available for Docker containers and
is fully managed by Docker engine. You can create a volume through Docker
commands and can share it within the Docker containers.

When you create a volume, it is stored within a directory on the Docker host
(/var/lib/docker/volumes/ on Linux) and is completely isolated from Docker
host. Multiple Docker containers can use the same volumes and can read-write
simultaneously.

When the container is not running, data still persist in volumes.

Bind Mounts or host volume


These are the host machine file systems which are mounted on Docker container
and this Docker don’t have control over it and host machine only manages it.

When you use a bind mount, a file or directory on the host machine is mounted
into a Docker container. Their performance is good, but containers have to rely
on the host machine’s filesystem having a specific directory structure available.

tmpfs Mounts
As the name suggests, these mounts are temporary and once the Docker
container is stopped the data present on these mounts is also lost.

tmpfs mounts are stored in the host system’s memory only and are never written
to the host system’s filesystem and thus does not hold data permanently.

It’s a temporary file store when remove the container tmpfs volume also
removed.
Below image from Docker website shows all these 3 mounts and depicts where the data
lives on the Docker host.

Which Mount Type to Use in Docker


Containers

Once you know what are the different types of mounts for Docker containers,
we are sure you can decide which one to use.

Volumes can be used if you want your Docker to manage the mount points and
data. You can also use this type of mount if the Docker host is not guaranteed to
have a given directory or file structure or want to store your container’s data on
a remote host or a cloud provider, rather than locally.

Bind mounts can be used if you want to save your data locally on the host itself
or want to share data from your Docker host to the Docker container especially,
configuration files, source code, etc.
tmpfs mounts are best for sensitive data or information and if you do not want
the data to be saved on the host machine or docker container. If you want to
store some secret keys you can use tmpfs, just for an example.

Docker volume lab :

1. $ docker volume

2. $ docker volume ls

3. $ docker volume create data_volue

4. $ docker volume ls

5. $ docker volume inspect data_volue

6. $ ls /var/lib/docker/volumes/ (docker area )

7. $ docker ps –a

8. $ docker images

9. $ docker volume ls

10. $ docker run –d –it –name ubuntu1 –mount

source=data_volue ,destination=/data Ubuntu /bin/bash

11. $ docker exec –it ubuntu1 /bin/bash

12.$ ls

13. $ cd data
14. $ touch test.txt
15.$ check with docker area possible to see the file
16. $ $ ls /var/lib/docker/volumes/ (docker area ) – second terminal check
this
17. $ docker stop ubuntu1

18.$ docker rm ubuntu1

19. Check docker area that test.txt file have or not its have the location

20. $ docker run –d –it –name ubuntu2 –mount

source=data_volue ,destination=/ram Ubuntu /bin/bash

21. $ docker exec –it ubuntu2 /bin/bash

22.$ ls

23. $ cd app

Docker bind mount lab :

1. $ docker run –d –it –name ramubuntu –v /data/mnt:test Ubuntu

/bin/bash

2. $ docker exec –it ramubuntu /bin/bash

3. $ cd test

4. $ touch king.txt

5. . second terminal – cd /data/mnt

6. Ls

7. Touch demo.txt

8. Main terminal

You might also like