9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Dockerでマウントする際は絶対パスで指定すること

Last updated at Posted at 2016-03-13

タイトルの通り。相対パスで指定して躓いたのでメモ。

前準備

$はホストでの操作。

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              c66docker0001       0881050dcb72        25 hours ago        202.6 MB

$ mkdir hostdir0001

$ echo "Hello Docker" > hostdir0001/testfile0001.txt

うまくいかない場合(相対パス)

$ docker run -v hostdir0001:/root/ctdir0001 -i -t centos:c66docker0001 /bin/bash
[root@bd1be231c0b0 /]#

うまくいく場合(絶対パス)

$ docker run -v /c/Users/hoshito/hostdir0001:/root/ctdir0001 -i -t centos:c66docker0001 /bin/bash
[root@ec0d30786546 /]# ls /root/ctdir0001/
testfile0001.txt

追記

realpathコマンドを使えば、絶対パスをコピペしなくてもいけます。

$ docker run -v $(realpath ./hostdir0001):/root/ctdir0001 -i -t centos:c66docker0001 /bin/bash
[root@eaf053b8bb1b /]# ls /root/ctdir0001/
testfile0001.txt
9
9
3

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?