markdown 关于Docker图像,容器和存储layer.md

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 关于Docker图像,容器和存储layer.md相关的知识,希望对你有一定的参考价值。

## Docker Images

Each Docker Image was built by stacking different Image Layers, each Image Layer represents an instructions in Image's dockerfile.

[](https://docs.docker.com/engine/userguide/storagedriver/images/container-layers.jpg)

When we create a new container, a writable layer is placed on top on underlying layers. We can call this layers is **Container Layer**.
All changes made in container (such as writing to files, modifing files or delete files) are written to this Container Layer.

[Multiple writable layers sharing the same read-only layers](https://docs.docker.com/engine/userguide/storagedriver/images/sharing-layers.jpg)


When you run the command below, you will see the **SIZE** column, which contains:
* The one *outside* the brankets is `size`: The amount of data (on disk) is used for **Container Layer**.
* The one *inside* the brankets if `virtual size`: The amount of data is used for **Read-only Layer** + `size`. So if two containers base on the same image, they share the same read-only data.

```
# docker ps -s
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES                   SIZE
3f5f33281a85        postgres            "docker-entrypoint..."   15 minutes ago      Up 15 minutes       5432/tcp            djangopostgresql_db_1   63B (virtual 287MB)
```
Docker Images are stored at `/var/lib/docker/<storage-driver>/`

## The Copy-on-write strategy 

Benefits:
* Reduces Images size.
* Reduces container start-up time.

## Docker volumes and storage driver

A data volume is:
* A directory or a file on Docker's host file system that is mounted directly into Docker containers.
* Not managed by storage driver.
* Not deleted after container exits. 

以上是关于markdown 关于Docker图像,容器和存储layer.md的主要内容,如果未能解决你的问题,请参考以下文章

markdown 如何删除未使用的Docker容器和图像

markdown docker cleanup guide:容器,图像,卷,网络

markdown docker cleanup guide:容器,图像,卷,网络

markdown docker cleanup guide:容器,图像,卷,网络

markdown docker cleanup guide:容器,图像,卷,网络

markdown docker cleanup guide:容器,图像,卷,网络