LoginSignup
18
11

More than 5 years have passed since last update.

dockerコンテナからマウントしたホストディレクトリへの操作が拒否される

Posted at

事象

コンテナからマウントしたディレクトリに対して操作を行うとアクセスが拒否される。

たとえばこんなコマンドを実行する。

docker run -i -v ${PWD}/hostdir:/guestdir -P centos touch /guestdir/test.txt

アクセス拒否され失敗する。

touch: cannot touch '/guestdir/test.txt': Permission denied

原因

SELinuxが邪魔している可能性がある。

SELinuxのが有効か無効かをgetenforceコマンドで確認
実行結果がEnforcingだとSELinuxが有効になっている。

回避する方法は2つ

その1:SELinuxを無効にする

一時的にSELinuxを無効にするには、

setenforce 0

その2:privilegedオプションを指定する

docker runコマンドを実行時に--privilegedオプションを指定する。

docker run --privileged -i -v ${PWD}/hostdir:/guestdir -P centos touch /guestdir/test.txt

詳しくは、docker runコマンドのリファレンス参照
Runtime Privilege, Linux Capabilities, and LXC Configuration

18
11
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
18
11