PodmanでローカルフォルダーをContainerへ共有する

いろいろな事情で、dockerの代わりにPodmanを使用している。runコマンドを実行する際に、ローカルフォルダーをContainerへ共有する

-v ローカルフォルダー:Container内のフォルダー

のオプションをつけても、Container内からフォルダーしか見えなくて、フォルダー内のファイルやサブフォルダーが見えない。

Google先生に聞いたら、以下の回答をもらった。

Common Causes and Solutions:
  • SELinux Context Issues:
    • Problem: SELinux, if enabled on the host, can restrict container access to mounted volumes.
    • Solution: Append :z or :Z to the volume mount option in your podman run command.
      • :z relabels the volume for shared use among multiple containers.
      • :Z relabels the volume for private use by a single container.
      • Example: podman run -v /host/path:/container/path:z my_image

つまり、オプションの最後に「:z」か「:Z」をつければよい。

試しに

-v ローカルフォルダー:Container内のフォルダー:Z

のオプションで再度runコマンドを実行したら、フォルダー内のファイルやサブフォルダーが見えるようになった。