‘Permission denied’ error when mounting a volume in Podman on RHEL 8.1 (Edited)
In Podman, I’m running a container as root, but I can’t access the mounted volume. The command ls -lh returns a “Permission denied” error, as does the command cat test.c when attempting to access the file /host/foobar/test.c.
Here’s my Dockerfile:
# Use Alpine Linux as a base image FROM alpine:latest
# Install necessary packages RUN apk --no-cache add bash gcc make
# Create a directory for source code RUN mkdir /src_dir
# Set working directory WORKDIR /src_dir
# Set up volume VOLUME [ "/src_dir" ]
I build the image and run the container with the following commands:
podman build -t my_image . podman run -it -v /host/foobar:/src_dir /bin/bash
How can I resolve this issue?
Answers
Erik Lindberg
7 months ago
Rating
The problem is related to SELinux policies on the host. When SELinux is enabled, you may encounter permission issues when accessing mounted volumes.
To allow Podman access to mounted volumes, you need to add the :z option when mounting the volume. This option tells SELinux to allow both the container and the host to access the mounted volume.
The command to run the container should be: