Skip to content

Instantly share code, notes, and snippets.

@jackpinto
Last active May 10, 2022 14:26
Show Gist options
  • Save jackpinto/23a9193385bf6239e43b21e5a198a3c3 to your computer and use it in GitHub Desktop.
Save jackpinto/23a9193385bf6239e43b21e5a198a3c3 to your computer and use it in GitHub Desktop.
How to create a local volume bind to host directory

Docker

Volume mount point

How to create a volume and set local host mount point.

Create volume first

docker volume create --driver local \
      --opt type=none \
      --opt device=/home/user/test \
      --opt o=bind \
      test_vol

Create on the fly with --mount

docker run -it --rm \
  --mount type=volume,dst=/container/path,volume-driver=local,volume-opt=type=none,volume-opt=o=bind,volume-opt=device=/home/user/test \
  foo

Inside a docker-compose file

  ...
  test:
    volumes:
      - bind-test:/var/lib/grafana

  volumes:
    bind-test:
      driver: local
      driver_opts:
        type: none
        o: bind
        device: /home/user/test

Credits to a stackoverflow answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment