22description : Learn the technologies that support storage drivers.
33keywords : container, storage, driver, btrfs, overlayfs, vfs, zfs
44title : Storage drivers
5- weight : 40
65aliases :
76 - /storage/storagedriver/imagesandcontainers/
87 - /storage/storagedriver/
98 - /engine/userguide/storagedriver/imagesandcontainers/
109---
1110
11+ {{< summary-bar feature_name="StorageDrivers"
12+ text="Use [ containerd] ( ../containerd.md ) instead.">}}
13+
1214To use storage drivers effectively, it's important to know how Docker builds and
1315stores images, and how these images are used by containers. You can use this
1416information to make informed choices about the best way to persist data from
@@ -170,7 +172,7 @@ docker.io/library/ubuntu:22.04
170172
171173Each of these layers is stored in its own directory inside the Docker host's
172174local storage area. To examine the layers on the filesystem, list the contents
173- of ` /var/lib/docker/<storage-driver> ` . This example uses the ` overlay2 `
175+ of ` /var/lib/docker/<storage-driver> ` . This example uses the ` overlay2 `
174176storage driver:
175177
176178``` console
@@ -326,7 +328,7 @@ layers are the same.
326328 Before BuildKit, the "classic" builder would produce a new "intermediate"
327329 image for each step for caching purposes, and the ` IMAGE ` column would show
328330 the ID of that image.
329-
331+
330332 BuildKit uses its own caching mechanism, and no longer requires intermediate
331333 images for caching. Refer to [ BuildKit] ( /manuals/build/buildkit/_index.md )
332334 to learn more about other enhancements made in BuildKit.
@@ -343,7 +345,7 @@ layers are the same.
343345 "sha256:07b4a9068b6af337e8b8f1f1dae3dd14185b2c0003a9a1f0a6fd2587495b204a"
344346 ]
345347 ```
346-
348+
347349 ``` console
348350 $ docker image inspect --format "{{json .RootFS.Layers}}" acme/my-final-image:1.0
349351 [
@@ -363,7 +365,7 @@ layers are the same.
363365 > [ !TIP]
364366 >
365367 > Format output of Docker commands with the ` --format ` option.
366- >
368+ >
367369 > The examples above use the ` docker image inspect ` command with the ` --format `
368370 > option to view the layer IDs, formatted as a JSON array. The ` --format `
369371 > option on Docker commands can be a powerful feature that allows you to
@@ -412,7 +414,7 @@ in a `copy_up` operation, therefore duplicating the file to the writable layer.
412414> applications, for example write-intensive databases, are known to be
413415> problematic particularly when pre-existing data exists in the read-only
414416> layer.
415- >
417+ >
416418> Instead, use Docker volumes, which are independent of the running container,
417419> and designed to be efficient for I/O. In addition, volumes can be shared
418420> among containers and don't increase the size of your container's writable
@@ -449,7 +451,7 @@ examines how much room they take up.
4494512 . Run the ` docker ps ` command with the ` --size ` option to verify the 5 containers
450452 are running, and to see each container's size.
451453
452-
454+
453455 ``` console
454456 $ docker ps --size --format "table {{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Size}}"
455457
@@ -460,35 +462,35 @@ examines how much room they take up.
460462 a5ff32e2b551 acme/my-final-image:1.0 my_container_2 0B (virtual 7.75MB)
461463 40ebdd763416 acme/my-final-image:1.0 my_container_1 0B (virtual 7.75MB)
462464 ```
463-
465+
464466 The output above shows that all containers share the image's read-only layers
465467 (7.75MB), but no data was written to the container's filesystem, so no additional
466468 storage is used for the containers.
467469
468470 {{< accordion title="Advanced: metadata and logs storage used for containers" >}}
469-
471+
470472 > [ !NOTE]
471473 >
472474 > This step requires a Linux machine, and doesn't work on Docker Desktop, as
473475 > it requires access to the Docker Daemon's file storage.
474-
476+
475477 While the output of ` docker ps ` provides you information about disk space
476478 consumed by a container's writable layer, it doesn't include information
477479 about metadata and log-files stored for each container.
478-
480+
479481 More details can be obtained by exploring the Docker Daemon's storage
480482 location (` /var/lib/docker ` by default).
481-
483+
482484 ``` console
483485 $ sudo du -sh /var/lib/docker/containers/*
484-
486+
485487 36K /var/lib/docker/containers/3ed3c1a10430e09f253704116965b01ca920202d52f3bf381fbb833b8ae356bc
486488 36K /var/lib/docker/containers/40ebdd7634162eb42bdb1ba76a395095527e9c0aa40348e6c325bd0aa289423c
487489 36K /var/lib/docker/containers/939b3bf9e7ece24bcffec57d974c939da2bdcc6a5077b5459c897c1e2fa37a39
488490 36K /var/lib/docker/containers/a5ff32e2b551168b9498870faf16c9cd0af820edf8a5c157f7b80da59d01a107
489491 36K /var/lib/docker/containers/cddae31c314fbab3f7eabeb9b26733838187abc9a2ed53f97bd5b04cd7984a5a
490492 ```
491-
493+
492494 Each of these containers only takes up 36k of space on the filesystem.
493495
494496 {{< /accordion >}}
@@ -502,13 +504,13 @@ examines how much room they take up.
502504 ``` console
503505 $ for i in {1..3}; do docker exec my_container_$i sh -c 'printf hello > /out.txt'; done
504506 ```
505-
507+
506508 Running the ` docker ps ` command again afterward shows that those containers
507509 now consume 5 bytes each. This data is unique to each container, and not
508510 shared. The read-only layers of the containers aren't affected, and are still
509511 shared by all containers.
510512
511-
513+
512514 ``` console
513515 $ docker ps --size --format "table {{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Size}}"
514516
0 commit comments