Podman is a new tool for managing containers. It's daemonless unlike Docker and built from the bottom up to play well with the Linux ecosystem. Podman is designed in the same way that traditional Linux tools are, it is lightweight, does not request more rights than necessary, and readily cooperates with SELinux.
What is Podman Unshare?
Podman unshare is useful for troubleshooting unprivileged activities and manually removing storage and other data associated with images and containers. It is also helpful to use the podman mount command. If unprivileged users want to mount and interact with a container, they must run podman unshare. Executing the podman mount fails for unprivileged users unless the user executes within a podman unshare session.
Step-by-Step Guide to Using the Podman Unshare Command for Debugging
Here is the step-by-step implementation of the Podman unshare command for debugging:
Step 1: Identify the Container
To get started, first identify the container you wish to debug. All currently running containers can be listed using.
podman psOutput:

Step 2: Mount the Container’s Filesystem
You must mount the container's filesystem to access it in the unshared environment before running podman unshare.
container_mount=$(podman mount <container-id>)Output:

Step 3: Enter the Unshare Environment
Enter the unshared environment now, where the root user in the user namespace is mapped to your user ID.
podman unshareOutput:

Step 4: Navigate to the Mounted Filesystem
Next, Go to the mounted container filesystem using the unshared shell.
cd $container_mountOutput:

Step 5: Check File Permissions and Ownership
To verify ownership and permissions, you can now examine the files and directories. For example.
ls -l /path/to/file/or/directoryOutput:

Step 6: Unmount the Container Filesystem
Lastly, unmount the container filesystem to clean up.
podman umount <container-id>Output:

Best Practices of Podman unshare command for debugging
- Mount the Container’s Filesystem Securely: Make sure the filesystem of the container is mounted correctly before using podman unshare. By doing this, you can have access to the root filesystem of the container without having to alter it directly. Upon completion, don't forget to unmount the filesystem.
- Document Any Changes Made: Mark down any modifications that you make when debugging in the private setting. This is necessary for future troubleshooting and, in case of need, for rolling back modifications.
- Unmount Filesystems After Debugging: Any container filesystems you mount for debugging should always be unmounted. This guarantees that no remaining mounts will interfere with container operations in the future and helps prevent data damage.
- Exit the Unshare Environment Promptly: Avoid staying in the unshared space for longer than required. Once you've finished debugging, quit the unshare shell to avoid any unwanted consequences.
Conclusion
In this article, we have learned about the Podman unshare command for debugging. The podman unshare command is an effective tool for troubleshooting container-related issues, notably those affecting user namespaces, file permissions, and user ID mapping.