Rootless Podman: How I Got My Home Directory Synced to a Container Volume

Why a Rootless Podman Volume for Your Home Directory?

Running services inside containers is a staple of most homelab setups. When you use Podman in rootless mode you keep the container runtime isolated from the host’s privileged space, which is great for security and for users who don’t have root access. A frequent pain point is that the container’s filesystem is isolated from your personal files. If you want a container to read or write your documents, photos, or configuration files, you need a way to expose a part of your home directory to the container. This post walks through a reliable method to mount a subdirectory of ~/ into a rootless Podman container, covering the trade‑offs, pitfalls, and a few tricks that make the setup robust.


1. The Problem Space

When you launch a rootless Podman container, it runs as your user and has a separate root filesystem. By default, the container sees only a minimal view of the host:

$ podman run --rm -it alpine ls -R /

The container can’t see your ~/Documents folder unless you explicitly bind‑mount it. A naive approach is to use --volume or -v:

podman run --rm -it \
  -v "$HOME/Documents:/home/user/Documents" \
  alpine ls /home/user/Documents

This works, but it has a few drawbacks:

  1. Hard‑coded paths – If you move the container to another machine, the absolute host path may not exist.
  2. Permission quirks – The container’s UID/GID mapping may not match the host’s, leading to “permission denied” errors.
  3. Security exposure – Mounting large parts of your home can give the container more access than intended.

A more flexible approach is to use Podman’s named volumes or volume plugins, but those still rely on a bind mount under the hood. The trick is to keep the bind mount minimal and controlled, while letting Podman manage the volume lifecycle.


2. The Rootless Volume Pattern

2.1 Create a Dedicated Sync Directory

Instead of exposing the whole ~/ tree, create a small directory that will hold the files you want the container to see:

mkdir -p ~/podman-sync

Place any files you need inside this folder. For example, if you run a personal wiki in a container, copy your markdown files there.

2.2 Use a Named Volume with a Bind Mount

Podman allows you to create a named volume that points to a host path via a bind mount. The syntax is:

podman volume create \
  --opt type=none \
  --opt device="$HOME/podman-sync" \
  --opt o=bind \
  sync

Now sync is a volume that resolves to ~/podman-sync. Inside the container, you can mount it anywhere you like:

podman run --rm -it \
  -v sync:/app/data \
  alpine ls /app/data

The container sees the same files you placed in ~/podman-sync. Because the volume is named, you can reuse it across multiple containers without repeating the bind‑mount options.

2.3 Keep UID/GID in Sync

Rootless containers map the host UID to a range of UIDs inside the container (by default 100000–165535). If you create files in ~/podman-sync with your regular user, the container will see them as UID 0 (root) inside the container, which is fine for read‑only access but can cause permission issues for writes.

To avoid this, set the --userns=keep-id flag when starting the container. This tells Podman to preserve the UID/GID mapping:

podman run --rm -it \
  --userns=keep-id \
  -v sync:/app/data \
  alpine sh -c 'id && ls -l /app/data'

Now the container sees your files with the same UID/GID as your host user, and write permissions work as expected.


3. Practical Example: A Self‑Hosted Wiki

Let’s walk through a real‑world scenario: running a lightweight wiki (e.g., Wiki.js) inside a rootless Podman container while keeping the markdown files in your home directory.

3.1 Prepare the Sync Folder

mkdir -p ~/podman-sync/wiki
cp ~/Documents/wiki/*.md ~/podman-sync/wiki/

3.2 Create the Volume

podman volume create \
  --opt type=none \
  --opt device="$HOME/podman-sync/wiki" \
  --opt o=bind \
  wiki-data

3.3 Pull and Run the Container

podman pull quay.io/bitnami/wikijs:latest

podman run --rm -d \
  --name wikijs \
  --userns=keep-id \
  -p 3000:3000 \
  -v wiki-data:/app/data \
  -e DB_TYPE=sqlite \
  -e DB_DIALECT=sqlite \
  -e DB_HOST=localhost \
  -e DB_PORT=5432 \
  -e DB_USER=wikijs \
  -e DB_PASS=wikijs \
  -e DB_NAME=wikijs \
  quay.io/bitnami/wikijs:latest

Now the Wiki.js instance reads and writes markdown files directly into ~/podman-sync/wiki. If you edit a file locally, the container sees the change immediately.


4. Trade‑offs and Caveats

Aspect Pros Cons
Rootless mode No root privileges, safer isolation Requires userns=keep-id for writes
Named volume + bind Reuse across containers, clean podman volume list Still a bind mount under the hood
Dedicated sync dir Minimal exposure, easy to audit Must remember to keep the folder tidy
UID/GID mapping Consistent permissions Requires explicit --userns=keep-id

4.1 Permission Errors

If you forget --userns=keep-id, you’ll see errors like:

Permission denied: /app/data/notes.md

Because the container sees the file as root, but the file on the host is owned by your user. Adding the flag fixes it.

4.2 SELinux / AppArmor

On systems with SELinux or AppArmor, the bind mount may be denied. Add the :z or :Z option to the bind mount if you’re using SELinux:

podman volume create \
  --opt type=none \
  --opt device="$HOME/podman-sync/wiki" \
  --opt o=bind,z \
  wiki-data

4.3 Cleaning Up

When you no longer need the volume, remove it:

podman volume rm wiki-data

The underlying host directory (~/podman-sync/wiki) remains untouched, so you can keep your files.


5. Troubleshooting Checklist

Symptom Likely Cause Fix
Container cannot read files Bind mount path wrong Verify $HOME/podman-sync exists
Container cannot write files UID/GID mismatch Add --userns=keep-id
SELinux denies access Context mismatch Add :z to bind options
Volume disappears after container stops Named volume not created Ensure podman volume create succeeded

6. Security Considerations

Rootless Podman already limits the container’s capabilities. By restricting the bind mount to a small, well‑known directory, you avoid giving the container arbitrary access to your home. If you need stricter isolation, consider using a read‑only bind mount (:ro) or a dedicated user‑group with limited permissions on the sync folder.


7. Takeaway

  • Rootless Podman is a great fit for home users who want container isolation without root.
  • Named volumes backed by bind mounts give you a clean, reusable way to expose parts of your home directory.
  • Keep UID/GID mapping consistent with --userns=keep-id to avoid permission headaches.
  • Audit the sync folder regularly; it’s the bridge between your host and containers.

With this pattern, you can run any containerized service—web servers, databases, or personal tools—while keeping your files in the familiar place of your home directory.

See also