TL;DR
realpath ..
で親ディレクトリの絶対パスを指定する.
Windowsのgit bashでもLinuxのbashでも動く-vオプションの親ディレクトリ指定方法
#!/usr/bin/env bash
MSYS_NO_PATHCONV=1 docker run -it --rm -v $(realpath ..):/input alpine ls /input
Windowsのmingw makeでもLinuxのmakeでも動く-vオプションの親ディレクトリ指定方法
.PHONY: all
all:
MSYS_NO_PATHCONV=1 docker run -it --rm -v $$(realpath ..):/input alpine ls /input
TL;DR= Too long; dont'read 長すぎるので読まない
背景
単純に-v ..:/input
と指定するとエラーになる
$ MSYS_NO_PATHCONV=1 docker run -it --rm -v ..:/input alpine ls /input
docker: Error response from daemon: create ..: ".." includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.
use absolute pathとあるので親ディレクトリ..
をrealpath ..
で絶対パスに変換するとGitBashのDocker Desktop for WindowsやRancher Desktop for WindowsでもLinuxでも正しく動作する
$ realpath ..
/c/Users/
$ MSYS_NO_PATHCONV=1 docker run --rm -v $(realpath ..):/input alpine ls /input # Docker Desktop
All Users
Default
Default User
Public
desktop.ini
lzpel
$ MSYS_NO_PATHCONV=1 docker run --rm -v $(realpath ..):/input alpine ls /input # Rancher Desktop
All Users
Default
Default User
Public
desktop.ini
lzpel
$ MSYS_NO_PATHCONV=1 docker run --rm -v $(realpath ..):/input alpine ls /input #CentOS
lost+found
misumi3104
Makefileでかくなら
.PHONY: all
all:
MSYS_NO_PATHCONV=1 docker run --rm -v $$(realpath ..):/input alpine ls /input