dockerで構成ファイルのマウントを行う方法

Docker使用時には、ホスト側にある設定ファイルをコンテナ内にマウントすることで設定ファイルを反映させることができます。設定ファイルのマウント方法は次のとおりです。

  1. ネイティブの日本語で、この文を言い換えてください。
docker run -v /path/to/host/config/file:/path/to/container/config/file image_name

ホストの構成ファイルパスが「/path/to/host/config/file」で、コンテナ内の構成ファイルパスは「/path/to/container/config/file」です。

  1. ネイティブな日本語に言い換える、-v のオプションは 1 つだけで済みます。
docker run -v /path/to/host/config/dir:/path/to/container/config/dir image_name

これでコンテナ内の /path/to/container/config/dir は、ホストの /path/to/host/config/dir と関連付けられます。

docker run --mount type=bind,source=/path/to/host/config/file,target=/path/to/container/config/file image_name

あるいは

docker run --mount type=bind,source=/path/to/host/config/dir,target=/path/to/container/config/dir image_name

注意点ですが、上記のコマンドに記載されている image_name は任意の Dockerイメージ名です。

コンテナ内でマウントされた設定ファイルを変更すると、ホストマシンの元のファイルも変更されます。また、ホストマシンの設定ファイルまたはディレクトリが存在しない場合は、Docker が自動的にそれらを作成します。

お役に立てば幸いです!

bannerAds