LoginSignup
64
59

More than 5 years have passed since last update.

DockerのVolumeのアクセス権限の問題について

Posted at

Dockerでは -v オプションを用いて、ホストディレクトリをマウントすることができる。

$ docker run -t -i -v /path/to/host-dir:/path/to/guest-dir your/image /bin/bash

ここで、マウントしたディレクトリのアクセス権限は、uid=1000, gid=1000, 755 となっており、
変更することはできない。

$ ls -l /path/to/
drwxr-xr-x   1 1000 1000      544 Feb 19 02:23 guest-dir
$ chown root /path/to/guest-dir
$ ls -l /path/to/
drwxr-xr-x   1 1000 1000      544 Feb 19 02:23 guest-dir
$ chmod 777 /path/to/guest-dir
$ ls -l /path/to/
drwxr-xr-x   1 1000 1000      544 Feb 19 02:23 guest-dir

つまり、マウントしたディレクトリに書き込めるのは、rootuid=1000 のユーザだけである。

これによって問題になるのは、例えば次のケースである。

  • Dockerコンテナ上にMySQLサーバーを構築し、かつデータを永続化する為に、ホストディレクトリを /var/lib/mysql にマウントする

ここで、デフォルトの設定のままだと、デーモンの動作ユーザが mysql なので rootuid=1000 のユーザに変更する必要がある。

my.cnf
[mysqld]
# user = mysql
user = 1000 # or root
64
59
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
64
59