Mounting the host filesystem

Intermediate Docker

Mike Metzger

Data Engineer

Container filesystems

  • Container instances each have their own filesystem
    • Based off the image the container was created with
  • Any changes are tied to that specific container instance
  • Any changes are maintained across restarts
    • For that instance only
  • New containers only have the data in the image, not instance specific changes

Container filesystems

Intermediate Docker

Sharing files or directories

  • Can attach specific files or directories to containers
  • Allows for persistence of data, without maintaining a specific container
  • Can upgrade container to new version but safely keep data / changes
  • Known as bind-mount
  • Can be read-only or read/write
  • Note: When files or directories are attached to a container, they are not accessible to the host until the container is shutdown
Intermediate Docker

Using the -v option

  • bind-mounts most often use the -v flag
  • -v <source>:<destination>
  • Multiple -v commands permitted
  • Can also use the --mount option
  • Note: bind-mount hides any content already present in the destination directory
docker run -v ~/html:/var/www/html \
       nginx
docker run 
       -v ~/pgdata:/opt/data \
       -v ~/pg.conf:/etc/pg.conf \
       postgresql
Intermediate Docker

Let's practice!

Intermediate Docker

Preparing Video For Download...