DevOps ~ Docker Data Management - rohit120582sharma/Documentation GitHub Wiki

By default all files created inside a container are stored on a writable container layer.

The data doesn’t persist when that container no longer exists, and it can be difficult to get the data out of the container if another process needs it.

This is called persistent data problem.

Docker has two options for containers to store files or data in the host machine, so that the files are persisted even after the container stops:

  • Volumes

    • Docker Volume is a solution of the persistent data problem. In other words, Volumes are used to persist data across the lifecycle of a container.
    • Volumes are created and used by Docker containers.
    • Volumes can be created by Volume command in Docker file.
    • Volume drivers let you store volumes on remote hosts or cloud providers.
    • Volumes are stored in a part of the host filesystem which is managed by Docker. It basically hosts the storage outside of the container and maps it to inside the container.
$ docker run -v <valume-name>:<path-into-container> <image-name>
  • Bind Mounts

    • Bind mount means a file or directory on the host machine is mounted into a container.
    • Mapping of host files into a container files.
    • Bind mounts may be stored anywhere on the host system.
    • Non-Docker processes or a Docker container can modify them at any time.
    • Bind mount can not be used in Dockerfile.
$ docker run -v <absoulute-file-path-from-host-machine>:<path-into-container> <image-name>
⚠️ **GitHub.com Fallback** ⚠️