2
2
description : Learn the technologies that support storage drivers.
3
3
keywords : container, storage, driver, btrfs, overlayfs, vfs, zfs
4
4
title : Storage drivers
5
- weight : 40
6
5
aliases :
7
6
- /storage/storagedriver/imagesandcontainers/
8
7
- /storage/storagedriver/
9
8
- /engine/userguide/storagedriver/imagesandcontainers/
10
9
---
11
10
11
+ {{< summary-bar feature_name="StorageDrivers"
12
+ text="Use [ containerd] ( ../containerd.md ) instead.">}}
13
+
12
14
To use storage drivers effectively, it's important to know how Docker builds and
13
15
stores images, and how these images are used by containers. You can use this
14
16
information to make informed choices about the best way to persist data from
@@ -170,7 +172,7 @@ docker.io/library/ubuntu:22.04
170
172
171
173
Each of these layers is stored in its own directory inside the Docker host's
172
174
local 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 `
174
176
storage driver:
175
177
176
178
``` console
@@ -326,7 +328,7 @@ layers are the same.
326
328
Before BuildKit, the "classic" builder would produce a new "intermediate"
327
329
image for each step for caching purposes, and the ` IMAGE ` column would show
328
330
the ID of that image.
329
-
331
+
330
332
BuildKit uses its own caching mechanism, and no longer requires intermediate
331
333
images for caching. Refer to [ BuildKit] ( /manuals/build/buildkit/_index.md )
332
334
to learn more about other enhancements made in BuildKit.
@@ -343,7 +345,7 @@ layers are the same.
343
345
"sha256:07b4a9068b6af337e8b8f1f1dae3dd14185b2c0003a9a1f0a6fd2587495b204a"
344
346
]
345
347
```
346
-
348
+
347
349
``` console
348
350
$ docker image inspect --format "{{json .RootFS.Layers}}" acme/my-final-image:1.0
349
351
[
@@ -363,7 +365,7 @@ layers are the same.
363
365
> [ !TIP]
364
366
>
365
367
> Format output of Docker commands with the ` --format ` option.
366
- >
368
+ >
367
369
> The examples above use the ` docker image inspect ` command with the ` --format `
368
370
> option to view the layer IDs, formatted as a JSON array. The ` --format `
369
371
> 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.
412
414
> applications, for example write-intensive databases, are known to be
413
415
> problematic particularly when pre-existing data exists in the read-only
414
416
> layer.
415
- >
417
+ >
416
418
> Instead, use Docker volumes, which are independent of the running container,
417
419
> and designed to be efficient for I/O. In addition, volumes can be shared
418
420
> among containers and don't increase the size of your container's writable
@@ -449,7 +451,7 @@ examines how much room they take up.
449
451
2 . Run the ` docker ps ` command with the ` --size ` option to verify the 5 containers
450
452
are running, and to see each container's size.
451
453
452
-
454
+
453
455
``` console
454
456
$ docker ps --size --format "table {{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Size}}"
455
457
@@ -460,35 +462,35 @@ examines how much room they take up.
460
462
a5ff32e2b551 acme/my-final-image:1.0 my_container_2 0B (virtual 7.75MB)
461
463
40ebdd763416 acme/my-final-image:1.0 my_container_1 0B (virtual 7.75MB)
462
464
```
463
-
465
+
464
466
The output above shows that all containers share the image's read-only layers
465
467
(7.75MB), but no data was written to the container's filesystem, so no additional
466
468
storage is used for the containers.
467
469
468
470
{{< accordion title="Advanced: metadata and logs storage used for containers" >}}
469
-
471
+
470
472
> [ !NOTE]
471
473
>
472
474
> This step requires a Linux machine, and doesn't work on Docker Desktop, as
473
475
> it requires access to the Docker Daemon's file storage.
474
-
476
+
475
477
While the output of ` docker ps ` provides you information about disk space
476
478
consumed by a container's writable layer, it doesn't include information
477
479
about metadata and log-files stored for each container.
478
-
480
+
479
481
More details can be obtained by exploring the Docker Daemon's storage
480
482
location (` /var/lib/docker ` by default).
481
-
483
+
482
484
``` console
483
485
$ sudo du -sh /var/lib/docker/containers/*
484
-
486
+
485
487
36K /var/lib/docker/containers/3ed3c1a10430e09f253704116965b01ca920202d52f3bf381fbb833b8ae356bc
486
488
36K /var/lib/docker/containers/40ebdd7634162eb42bdb1ba76a395095527e9c0aa40348e6c325bd0aa289423c
487
489
36K /var/lib/docker/containers/939b3bf9e7ece24bcffec57d974c939da2bdcc6a5077b5459c897c1e2fa37a39
488
490
36K /var/lib/docker/containers/a5ff32e2b551168b9498870faf16c9cd0af820edf8a5c157f7b80da59d01a107
489
491
36K /var/lib/docker/containers/cddae31c314fbab3f7eabeb9b26733838187abc9a2ed53f97bd5b04cd7984a5a
490
492
```
491
-
493
+
492
494
Each of these containers only takes up 36k of space on the filesystem.
493
495
494
496
{{< /accordion >}}
@@ -502,13 +504,13 @@ examines how much room they take up.
502
504
``` console
503
505
$ for i in {1..3}; do docker exec my_container_$i sh -c 'printf hello > /out.txt'; done
504
506
```
505
-
507
+
506
508
Running the ` docker ps ` command again afterward shows that those containers
507
509
now consume 5 bytes each. This data is unique to each container, and not
508
510
shared. The read-only layers of the containers aren't affected, and are still
509
511
shared by all containers.
510
512
511
-
513
+
512
514
``` console
513
515
$ docker ps --size --format "table {{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Size}}"
514
516
0 commit comments