WSL1&Docker Desktop環境でファイルのマウント

Dockerコンテナを起動時にローカルのデータディレクトリや設定ファイルをコンテナ内にマウントしたい場合があると思います。しかし、CドライブをDocker DesktopのVMはを/cにマウントし、WSLは/mnt/cにマウントするため、

$ docker run -v ./conf/nginx.conf:/etc/nginx/nginx.conf

ような形で、ローカル側のファイルを指定すると、次のようなエラーが発生します。

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/mnt/c/workspace/test-app/config/nginx.conf" to rootfs a
t "/etc/nginx/nginx.conf": mount /mnt/c/workspace/test-app/config/nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/14), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

これを防ぐにはWSL上でも/cから始まるパスを利用するようにします。

まず/cディレクトリを作成します。

$ sudo mkdir /c

次に/cを/mnt/cにマウントします。

$ sudo mount --bind /mnt/c /c

/c配下のプロジェクトディレクトリに移動してDockerを起動します。

$ cd /c/workspace/test-app
$ docker run -v ./conf/nginx.conf:/etc/nginx/nginx.conf

※/cをマウントしても、/mnt/c配下のプロジェクトディレクトリではエラーのままになりますので、注意してください。

コメントを残す

Required fields are marked *.


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

Top