0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitbashでDocker Desktopを起動し、volumeで親ディレクトリ..を指定する方法について

Last updated at Posted at 2024-06-23

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?