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?

More than 1 year has passed since last update.

docker Operation not permitted & The path is not shared from the host and is not known to Docker.

Last updated at Posted at 2023-03-06

背景

Redmine on Docker にプラグイン導入を簡単に, https://qiita.com/hadacchi/items/ca10939ca016147e225a を参考に Redmine Containerを建てようとすると下記事象に遭遇した。両者に遭遇すると原因が良く分からなくなるので、事象ごとの対策を記載しておく。

環境: Ubuntu22.04 + Docker Desktop

事象と対策

事象 1. Operation not permittedとなる。

root@xxxxxx:/mnt/c/Users/xxxxx/docker/redmine# docker-compose up  //WSL2のconsoleだがUbuntu22でも同様のErrorとなる。
[+] Running 3/3
 ⠿ Network redmine_default      Created                                                                            0.1s
 ⠿ Container redmine-pdb-1      Created                                                                            0.1s
 ⠿ Container redmine-redmine-1  Created                                                                            0.2s
Attaching to redmine-pdb-1, redmine-redmine-1
redmine-pdb-1      | chmod: /var/lib/postgresql/data: Operation not permitted
redmine-pdb-1      | The files belonging to this database system will be owned by user "postgres".

原因: ホストOSで使っているユーザとコンテナ内で使っているユーザのUIDとGIDが不一致になるため [1]
対策:

  • 先にホスト側でディレクトリを作成しない。
  • docker-compose upで、先にコンテナ内のUID/GIDを持つディレクトリをホスト側に作成し、更にchmod 777 * で権限を持たせる。

備考: WSL2 環境だとUID/GIDを自動生成してくれないので注意。Ubuntu22はディレクトリが無い場合に自動生成してくれる。

[1] Dockerのvolumeでpermission deniedが発生した場合の解決法, https://tech-blog.rakus.co.jp/entry/20200826/docker

事象 2. hostからcontainerへpathが共有されていない

test@test-virtual-machine:~/Downloads/redmine$ docker-compose up
Removing redmine_pdb_1
Recreating 94ba35a425ab_redmine_pdb_1 ... error

ERROR: for 94ba35a425ab_redmine_pdb_1  Cannot start service pdb: Mounts denied: 
The path /opt/server/postgres is not shared from the host and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing.
See https://docs.docker.com/ for more info.

対策: Docker DesktopのSetting > Resources > File sharing にてpathを共有する[2]

[2] Docker compose up -d のエラー対処法 Error response from daemon Mounts denied The path backend is not shared from the host and is not known to Docker, https://poppotennis.com/posts/docker-error-host-is-not-known

その他

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?