30
Docker Storage Internals Amit Shukla Docker Inc 1

Docker Storage Internals - Amit Shukla

Embed Size (px)

Citation preview

Page 1: Docker Storage Internals - Amit Shukla

Docker Storage InternalsAmit Shukla Docker Inc

1

Page 2: Docker Storage Internals - Amit Shukla

Introduction• Engineer

• Manage Storage and Orchestration teams @ Docker

• Background in Data storage systems and Distributed systems

• Twitter, Microsoft, Teradata

• Univ of Wisconsin, IIT Madras

• Love building software to solve real problems

• @amits: eclectic stream of geeky things

2

Page 3: Docker Storage Internals - Amit Shukla

Agenda

• Docker Introduction

• Docker Image storage

• Storage drivers

• Volumes

3

Page 4: Docker Storage Internals - Amit Shukla

Docker• Open source projects

• Engine, Swarm, Compose, Machine, Registry, …

• Company

• Shepherd of open source projects

• Commercial: Hub, DTR

4

Page 5: Docker Storage Internals - Amit Shukla

What are containers?

Server

Host OS

Hypervisor

Guest OS

Guest OS

Guest OS

Bins/ Libs

Bins/ Libs

Bins/ Libs

App A

App A’

App B

VM

Server

Host OS

Docker Engine

Bins/ Libs Bins/ Libs

App A

App A’

App B

App B

App B’

App B’

App B’

App B’Container

Host Level Virtualization

OS Level Virtualization

5

Page 6: Docker Storage Internals - Amit Shukla

Docker: portability

6

Page 7: Docker Storage Internals - Amit Shukla

Demo

• Pull a container Image from the Registry (docker hub)

• Start container

• Dockerfile for container

7

Page 8: Docker Storage Internals - Amit Shukla

Diving deeper: Image storage

8

Page 9: Docker Storage Internals - Amit Shukla

Local Image Storage

• Two enabling technologies

• Copy on Write

• Union File Systems

9

Page 10: Docker Storage Internals - Amit Shukla

Copy on Write• Common paradigm in Unix

• fork(): start processes by making a copy of an existing process

• Single shared copy of data, until it is modified

• Without this containers

• would take forever to start

• would take a lot of space

10

Page 11: Docker Storage Internals - Amit Shukla

Union File Systems• Represent a logical file system by grouping

different directories and/or files (branches)

• Each branch represents a layer in a Docker image

• Allows images to be constructed / deconstructed as needed vs. a huge monolithic image (ala traditional virtual machines)

• When a container is started a writeable layer is added to the “top” of the file system

11

Page 12: Docker Storage Internals - Amit Shukla

Layers

12

Page 13: Docker Storage Internals - Amit Shukla

Example: AUFS• Layers as “plates of glass”

• Only top most plate of glass is writable

• RO => find the file in the first plate of glass

• RW => copy file to top-most plate of glass (copy up), and then open it for write

• Delete => whiteout the file

13

Page 14: Docker Storage Internals - Amit Shukla

Union File Systems: Advantages

• Memory usage:

• files have same inode => kernel shares copy of file for multiple containers in page cache

• Faster create/destroy times:

• Scanning for KSM (Kernel same-page merging) not needed

• Key to quick startup times for Docker containers14

Page 15: Docker Storage Internals - Amit Shukla

Demo

• Explore where images live

15

Page 16: Docker Storage Internals - Amit Shukla

Storage drivers

• Implement Union file system for image composition and CoW

• “Batteries included but pluggable”

• Flexibility to choose a solution

• AUFS, OverlayFS, Device Mapper, BTRFS, VFS, ZFS

16

Page 17: Docker Storage Internals - Amit Shukla

AUFS• Oldest driver, and default for Ubuntu

• Works at the file level

• Scales really well due to memory sharing

• Not in mainline kernel

• Hence the need for linux-image-extra-virtual as part of the install process

• Not well suited for working with large files (logs, databases, etc)

• Use volumes instead

• Containers with a lot of layers will result in many branches and long traversal times

17

Page 18: Docker Storage Internals - Amit Shukla

Device Mapper• Contributed by Red Hat

• Has some nice high end features (RAID, disk encryption, snapshots)

• Works at the block level with thin provisioning

• Can snapshot at any time

• More complex than AUFS

• Working at the block level reduces visibility into the diffs between images and containers

• Does not share pages in memory, so density is lower than AUFS

• Need to be deliberate about tuning to get good perf

• Docker uses loop device by default, poor performance

• Put data and metadata on real devices18

Page 19: Docker Storage Internals - Amit Shukla

Recommended Storage driver?

• No best storage driver :-(

• High density Paas => aufs (if available), overlayfs (otherwise)

• Don't put big files in the container file system

• Otherwise use the file system you have the most experience with operating in production

19

Page 20: Docker Storage Internals - Amit Shukla

Volumes

20

Page 21: Docker Storage Internals - Amit Shukla

What are Volumes?• A directory mounted inside my container that exists

outside the union file system

• Directory's lifetime is independent of the container lifetime

• Create via Dockerfile or CLI

• Can map to existing directory on host or remote NFS device

• Share data between containers

21

Page 22: Docker Storage Internals - Amit Shukla

When should I use a volume?• Recommended almost always

• Faster to write outside the union file system: databases, log files

• Perf study: http://jam.sg/blog/mongodb-docker-part-2/

• Significant increase in IOPs and throughput

• Sharing data between containers

• Sharing data between host and container (e.g.: source code)

22

Page 23: Docker Storage Internals - Amit Shukla

Demo• Instantiating a volume (example)

• Command line

docker run -d -v /www -p 80:80 --name mynginx nginx

• Dockerfile

FROM nginx

VOLUME /www

23

Page 24: Docker Storage Internals - Amit Shukla

Demo

• Find Volume located within a container

• Add a file to it

24

Page 25: Docker Storage Internals - Amit Shukla

• Mounting host directory into container

• Not portable (scenario: source code)

• Data only containers -- subsumed by "docker volume create"

25

Page 26: Docker Storage Internals - Amit Shukla

Named Volumes• Named volumes - volumes are managed

resources with their own commands

• Docker volume create

• Docker volume inspect

• Docker volume ls

• Docker volume rm

26

Page 27: Docker Storage Internals - Amit Shukla

Demo (1.9+ only)

• Create a volume via command line

• Inspect container to find mount point

• Run a script in a container

• Look inside volume directory

• Start a new container that reuses volume

27

Page 28: Docker Storage Internals - Amit Shukla

Volume Plugins• Allows docker to work with other storage backends

• Docker tools work as usual

• Backends: Ceph, EMC, portworx, Blockbridge

You can write your own:

http://docs.docker.com/engine/extend/plugins_volume/

28

Page 29: Docker Storage Internals - Amit Shukla

Summary

• Docker overview

• Image storage

• Volumes

29

Page 30: Docker Storage Internals - Amit Shukla

Questions?

30