Permission denied in volumens

When running podman run and mounting a local directory, you might get a Permission denied when accessing the directory inside the container.

The man-page of podman-run explains why:

Write Protected Volume Mounts

You can add :ro or :rw option to mount a volume in read-only or read-write mode, respectively. By default, the volumes are mounted read-write.

Chowning Volume Mounts

By default, Podman does not change the owner and group of source volume directories mounted into containers. If a container is created in a new user namespace, the UID and GID in the container may correspond to another UID and GID on the host.

podman run -it -v local_dir:/container_dir:z ubuntu:latest bash

Alternative change the user id:

podman run --rm -it --userns=keep-id --user=$(id -ur):$(id-gr) -v local-dir:/container_dir:Z ubuntu:latest bash