Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save quangkeu95/967ba6be5ff9258004ea610ca2a07ecc to your computer and use it in GitHub Desktop.
Save quangkeu95/967ba6be5ff9258004ea610ca2a07ecc to your computer and use it in GitHub Desktop.

Docker Images

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

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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment