Skip to content

Instantly share code, notes, and snippets.

@kamal-github
Last active November 4, 2018 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamal-github/d70c52fa48f18f9bb86c8189cbf4ddda to your computer and use it in GitHub Desktop.
Save kamal-github/d70c52fa48f18f9bb86c8189cbf4ddda to your computer and use it in GitHub Desktop.
Docker: Bind Mount vs Volumes

Bind Mount vs Volumes

  • When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its full or relative path on the host machine. By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents.
  • The file or directory does not need to exist on the Docker host already. It is created on demand if it does not yet exist.
  • Both allow sharing contents amoung containers
  • Prepopulated contents obsucured in case of Bind Mount while Volume sync the contents from containers to Docker host.
  • Bind Propagation exixt only in Bind Mount.
  • Unlike a bind mount, you can create and manage volumes outside the scope of any container.
    • Create a volume: $ docker volume create my-vol
 --name devtest \
 -v myvol2:/app \
 nginx:latest
 docker run -d \
-it \
--name devtest \
-v "$(pwd)"/target:/app \
nginx:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment