This procedure followed on a Red Hat Enterprise Linux 9. By default, podman uses /var/lib/containers/storage as a storage to store images. However, this can be changed based-on the requirements of a project or case where user doesn’t have write permission on that location. This document outlines the process to change the storage location to a custom location where user has the write permission.
Assume:
- User name is usrdev
- Custom location is /app/containers/storage, where usrdev has write permission
- Also assume that se-linux is enable in the host system
Create a storage.conf file at ~/.config/containers directory.
# create a directory for config file
mkdir -p ~/.config/containers
# create a storage.conf for custom config
touch ~/.config/containers/storage.conf
Check user id, which will be used in the config file in the next section
id usrdev
# uid=1000(usrdev) gid=1000(usrdev) groups=1000(usrdev)
Add following minimal contents in the ~/.config/containers/storage.conf for the custom storage location.
# vi ~/.config/containers/storage.conf
[storage]
driver = "overlay"
runroot = "/run/user/1000"
graphroot = "/app/containers/storage"
Now add/copy linux related context to the target storage location as a sudo privilege.
# run as a sudo privilege
semanage fcontext -a -e /var/lib/containers/storage /app/containers/storage
restorecon -R -v /app/containers/storage
Check container related se-linux context at target storage location folder.
ls -laZ /app/containers/storage
Now you can able to pull/load/run images that will be used storage location at /app/containers/storage.