Mounting a volume into an already-running Podman container lets you add or replace files without restarting the container. This is handy for injecting configuration files, sharing data with a host process, or updating code in a development container. Unlike `podman run -v`, which mounts at container creation, this method uses the `podman mount` command on the container’s root filesystem. You must have the container’s ID or name, and the container must be running (or at least existing). Podman’s `mount` command works with the container’s storage driver, so it requires that the container uses a writable layer (which is default). This guide walks you through the process, including common pitfalls and troubleshooting.
What You’ll Need
- A running Podman container (or one that exists, even if stopped).
- Podman installed (version 3.0 or later recommended).
- Root or sudo access, unless you are running Podman in rootless mode (then you own the container).
- The container’s ID or name (find with `podman ps`).
- A destination directory on the host that you want to mount into the container.
Step-by-Step
- Identify your container. Run `podman ps` to list running containers. Note the container ID (first column) or name (last column). If the container is stopped, use `podman ps -a`.
- Get the container’s mount point. Run `podman mount `. This mounts the container’s root filesystem to a host directory and prints that path. For example: `podman mount my-container` outputs something like `/var/lib/containers/storage/overlay/…/merged`. If the container is already mounted, it will print the existing mount point.
- Note the mount point. Copy the output path. You’ll use it to access the container’s filesystem from the host.
- Create a directory on the host for your volume data. If you don’t have one, create it, e.g., `mkdir -p /home/user/myvolume`. This is the source directory you want to appear inside the container.
- Bind-mount the host directory into the container’s filesystem. Use the `mount` command with `–bind` to attach your host directory to a specific path inside the container’s mount point. For example, to mount `/home/user/myvolume` to `/data` inside the container, run: `sudo mount –bind /home/user/myvolume /var/lib/containers/storage/overlay/…/merged/data`. If the target path doesn’t exist, create it first: `sudo mkdir -p /var/lib/containers/storage/overlay/…/merged/data`.
- Verify the mount. Check that the files appear inside the container. You can do this by running `podman exec ls /data` or by inspecting the host mount point with `ls /var/lib/containers/storage/overlay/…/merged/data`.
- Use the container normally. The volume is now live. Changes made on the host or inside the container are visible on both sides.
- Unmount when done (optional). To detach the volume, first unmount the bind mount: `sudo umount /var/lib/containers/storage/overlay/…/merged/data`. Then you can unmount the container root filesystem with `podman unmount `.
Common Mistakes
- Forgetting to create the target directory. If the path inside the container doesn’t exist, the bind mount will fail. Always `mkdir -p` the target.
- Mounting to the container’s root mount point incorrectly. You must mount to a subdirectory under the container’s mount point, not the mount point itself (unless you intend to replace the entire root).
- Using `podman mount` on a stopped container. It works, but the container’s filesystem is read-only? Actually, it mounts read-write, but the container process is not running, so changes won’t be seen until start. If you need to add files to a stopped container, consider using `podman cp` instead.
- Not using `sudo` when required. In rootful Podman, the mount point is owned by root, so bind mounts need root privileges.
- Assuming the mount persists after container restart. This method is temporary. If the container is restarted, the bind mount is lost. For persistent mounts, use `podman run -v` or a named volume.
Tips
- Use a named volume for persistent data. Instead of manual bind mounts, consider `podman volume create` and mount it with `-v` at container creation. This is more robust and survives restarts.
- Check the mount point with `podman mount` without arguments. It lists all mounted containers and their mount points, which is useful if you forget.
- Use `podman unshare` for rootless containers. If you’re rootless, you may need to enter the user namespace to access the mount point: `podman unshare` then run the mount command.
- For development, consider using `podman run –rm -v`. It’s simpler and avoids manual cleanup.
- Always unmount after use. Leaving extra mounts can cause confusion and waste space.
Troubleshooting
- “Error: container not found” – Check the container ID/name. Use `podman ps -a` to list all.
- “Error: mount point not found” – The container may be stopped or not using a writable layer. Start the container first or use `podman start`.
- “Permission denied” when mounting – You need root privileges in rootful mode. Use `sudo`. In rootless mode, ensure you own the container and use `podman unshare`.
- Bind mount fails with “no such file or directory” – The target directory inside the container doesn’t exist. Create it with `sudo mkdir -p` on the mount point path.
- Changes not visible inside container – Verify you mounted to the correct path. The container’s process may have cached the directory; try `podman exec` to check. Also, ensure the bind mount is actually on the merged layer.
- Mount point disappears after container stop – That’s normal. The mount is tied to the container’s lifecycle. Use `podman mount` again after start.
Frequently Asked Questions
- Can I mount a volume into a running container without stopping it? Yes, that’s exactly what this guide does. The container keeps running while you mount.
- Will the mount survive a container restart? No. This method is temporary. For persistent mounts, use `-v` at container creation or a named volume.
- Is it safe to mount a host directory into a running container? Generally yes, but be careful with sensitive data. The container will have read/write access to that host directory, so ensure permissions are appropriate.
- Can I mount a volume into a rootless container? Yes, but you may need to use `podman unshare` to access the mount point, and the mount point is in your user namespace.
- What’s the difference between `podman mount` and `podman run -v`? `podman mount` mounts the container’s root filesystem to the host for maintenance. `-v` creates a volume mount at container start. This guide uses `podman mount` plus a bind mount to add a volume after start.
- Can I unmount just the bind mount without unmounting the container? Yes, use `sudo umount /path/to/mountpoint` to remove the bind mount, leaving the container’s root filesystem mounted.