0% found this document useful (0 votes)
13 views19 pages

07 - Docker Storage

This chapter discusses Docker's data management, focusing on the distinction between stateless and stateful containers and the various storage options available. It explains the use of Docker volumes and bind mounts for data persistence, highlighting the importance of managing data outside of container lifecycles. Additionally, it covers the creation, sharing, and characteristics of persistent and ephemeral volumes in Docker environments.

Uploaded by

rizqi.aiml01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views19 pages

07 - Docker Storage

This chapter discusses Docker's data management, focusing on the distinction between stateless and stateful containers and the various storage options available. It explains the use of Docker volumes and bind mounts for data persistence, highlighting the importance of managing data outside of container lifecycles. Additionally, it covers the creation, sharing, and characteristics of persistent and ephemeral volumes in Docker environments.

Uploaded by

rizqi.aiml01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

• In this chapter, you will learn how Docker manages data.

• It is crucial to know where to store your data and how your services will
access it.
• This chapter will explore running stateless versus stateful Docker
containers, and will delve into the configuration setup options for storage
for different applications.
• By the end of the chapter, you will be able to distinguish between the
different storage types in Docker and identify the container's life cycle and
its various states.
• You will also learn how to create and manage Docker volumes.
• There are two types of data storage in Docker.
• The first one is storage that is tightly coupled to the container life cycle.
• If the container is removed, the files on that storage type are also removed and
cannot be retrieved.
• These files are stored in the thin read/write layer inside the container itself.
• This type of storage is also known by other terms, such as the local storage, the
graphdriver storage, and the storage driver.
• The second section of the chapter explores stateless and stateful
services.
• Stateful applications are the ones that need persistent storage, such as databases
that persist and outlive the container.
• In stateful services, the data can still be accessed even when the container is
removed.
• The container stores the data on the host in two ways: through
volumes and bind mounts.
• Using a bind mount is not recommended because the bind mount
binds an existing file or directory on the host to a path inside the
container.
• Containers are crafted from their base images.
• The container inherits the filesystem of the image by creating a thin
read/write layer on top of the image layers' stack.
• The base images stay intact, and no changes are made to them.
• All your changes happen in that top layer of the container.
• Containers and services can run in two modes: stateful and stateless.
• A stateless service is the one that does not retain persistent data.
• This type is much easier to scale and update than the stateful one.
• A stateful service requires persistent storage (as in databases).
• Therefore, it is harder to dockerize because stateful services need
synchronization with the other components of the application.
• Apache and NGINX are examples of stateless services, while databases
are examples of stateful containers.
• We can use volumes to save persistent data without relying on the
containers.
• You can think of a volume as a shared folder. In any instance, if you
mount the volume to any number of containers, the containers will be
able to access the data in the volume.
• There are two ways to create a volume:
• Create a volume as an independent entity outside any container by using the
docker volume create subcommand.
• Creating a volume as an independent object from the container adds flexibility to
data management.
• These types of volumes are also called named volumes because you specify a
name for it, rather than leaving the Docker Engine to generate an anonymous
numeric one.
• Create a volume by using the --mount or -v or --volume options in the
docker container run subcommand.
• Docker creates an anonymous volume for you. When the container is removed,
the volume will not be removed as well unless indicated explicitly by using the -v
option to the docker container rm subcommand or using a docker volume
rm subcommand.
• Use the docker system df command to find out the size of all the
Docker objects in your system
• You can get more detailed information about the Docker objects by
adding the -v option to the docker system df command
• Run the docker volume ls subcommand to list all the volumes that
you have on your system
• There are two types of volumes: persistent and ephemeral ones.
• What we have seen so far is persistent volumes, which are between
the host and the container.
• To share the volume between containers, we use the --volumes-
from option.
• This volume exists only as long as it is being used by a container.
• When the last container using the volume exits, the volume
disappears.
• This type of volume can be passed from one container to the next but
is not saved.
• These volumes are called ephemeral volumes.
• Volumes can be used to share log files between the host and the
container or between containers.
• It is much easier to share them on a volume with the host so that even
if the container was removed for an error, we can still track the error
by checking the log file on the host after the container's removal.
• Another common use of volumes in practical microservices
applications is sharing the code on a volume.
• The advantage of this practice is that you can achieve zero downtime.
The developer team can edit the code on the fly.
• Note that volumes are not part of images, so the data saved on
volumes won't be uploaded or downloaded with images.
• The volumes will be engraved in the image, but not its data.
• Therefore, if you want to save certain data in an image, save it as a file,
not as a volume.











You might also like