Skip to content

Instantly share code, notes, and snippets.

@Ningensei848
Created January 10, 2021 08:07
Show Gist options
  • Save Ningensei848/675f4286613efed41fc9d31b709aaadb to your computer and use it in GitHub Desktop.
Save Ningensei848/675f4286613efed41fc9d31b709aaadb to your computer and use it in GitHub Desktop.
dockerのvolume周りの設定のメモ

ホストにマウントしたボリュームでマウントする

(こっちは追記があるかも=> dockerのメモ | zenn.dev


何を言ってるかわからねえと思うが,以下の前提がある.
1. ホストのディレクトリをコンテナにマウントしたい 2. パスで指定するのではなく**名前をつけたい** + **`volume` として扱いたい** 3. が,何らかの不手際で `volume` と**一緒にディレクトリが削除されては困る** 4. __non-empty-data__ であっても正常に動作してほしい
version: "3.9"

services:
  app:
    .
    .
    volumes:
      - datastore:/path/to/dir/in/container

volumes:
  datastore:
    driver: local
    # cf. https://bit.ly/35tRa66 --> but this solution needs `driver: local` or somthing driver.
    driver_opts:
      type: none
      device: ${PATH_TO_YOUR_DIRCTORY}
      o: bind

ハードコーディングが避けられるし,ボリュームつくって使い回せるしサイコーな可能性が高いです[要検証].PATH_TO_YOUR_DIRCTORY.env とかグローバルな環境変数とかに設定するといいかと思います.


動作環境は以下の通り.Macとかで実現できなかったらスマン…

  • Docker desktop for Windows: 3.0.4(51218)
    • docker engine: 20.10.2
    • docker compose: 1.27.4
  • settings.General: ✅Use the WSL 2 based engine
  • settings.Resources.WSL-Integration: ✅Enable integration with my default WSL distro
参考文献:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment