Run the command docker inspect <container_name_or_id> to check if a Docker volume is mounted and view its mount details. This outputs full container configuration, including the 'Mounts' section listing all attached volumes. Look for the 'Source' (host path), 'Destination' (container path), and 'Mode' (read/write permissions) fields.

  1. Run docker ps to list running containers and identify the container name or ID.
  2. Execute docker inspect <container_name_or_id> to retrieve detailed container configuration.
  3. Scan the output for the "Mounts" array to confirm volume presence and configuration.
  4. Verify the "Source" and "Destination" paths match expected values.
  5. Check the "Mode" field for rw (read-write) or ro (read-only) as needed.
  6. If using named volumes, run docker volume inspect <volume_name> to confirm volume exists and is correctly mapped.
  7. Test file access by writing to the mounted path inside the container and verifying it appears on the host.

What the Mounts Section in Docker Inspect Shows

The "Mounts" section in docker inspect output is a JSON array listing all volumes and bind mounts attached to the container. Each entry contains specific fields that define the mount’s behavior and location. These fields are standardized and consistent across Docker versions.

Key fields include:

  • Type: Either bind (host directory mapped directly) or volume (managed by Docker).
  • Source: The absolute path on the host machine (e.g., /home/user/data).
  • Destination: The path inside the container where the volume is mounted (e.g., /app/data).
  • Mode: Permissions mode, typically rw (read-write) or ro (read-only).
  • RW: Boolean value (true or false) indicating if the mount is writable.
  • Propagation: Mount propagation setting, common values are rprivate or rshared.

Example snippet from docker inspect:


"Mounts": [
  {
    "Type": "volume",
    "Name": "mydata",
    "Source": "/var/lib/docker/volumes/mydata/_data",
    "Destination": "/data",
    "Driver": "local",
    "Mode": "rw",
    "RW": true,
    "Propagation": ""
  }
]

If the "Mounts" array is empty, no volumes or bind mounts are attached to the container.

How to Verify Volume Mounts with Docker Exec

After confirming the mount exists in docker inspect, test access by writing a file inside the container. Use docker exec to run a command in the running container and interact with the mounted directory.

Run this command to create a test file in the mounted path:

docker exec <container_name_or_id> touch /data/test_file.txt

Replace /data with the actual Destination path from the inspect output. Then, on the host machine, navigate to the Source path and confirm the file exists. For example, if the source is /var/lib/docker/volumes/mydata/_data, run:

ls /var/lib/docker/volumes/mydata/_data

The file test_file.txt should appear. If it does not, the mount is not functioning correctly. Permissions on the host directory may block write access even if the mount is configured.

Common Errors When Checking Docker Volume Mounts

One frequent issue is a mismatch between the container’s expected mount path and the actual Destination. If an application inside the container writes to /app/uploads but the volume is mounted at /data, files will not be persisted as intended. Always confirm the Destination matches the application’s expected directory.

Another common error is incorrect permissions on the host directory. If the host path is owned by root and the container process runs as a non-privileged user, write operations will fail. Use ls -ld <host_path> to check ownership and permissions. Adjust using chown or chmod as needed, typically allowing group or world write access if appropriate for the environment.

If using bind mounts (host paths), ensure the directory exists on the host before starting the container. Docker does not create parent directories for bind mounts. Missing directories result in silent failures or empty mounts. For named volumes, Docker creates them automatically if they do not exist.

Difference Between Bind Mounts and Named Volumes

Bind mounts link a specific host directory directly to a container path. The Source is an explicit host path (e.g., /home/user/config). Changes are immediately visible on the host, and the directory persists independently of Docker. Bind mounts are useful for development and configuration files.

Named volumes are managed by Docker and stored in /var/lib/docker/volumes/ by default. The Source is a Docker-managed path, and the volume lifecycle is tied to Docker commands like docker volume create and docker volume rm. Named volumes are preferred for production data because they are easier to back up, migrate, and manage across systems.

Use docker volume ls to list all named volumes. Use docker volume inspect <volume_name> to view the actual host path and driver settings. Bind mounts do not appear in docker volume ls output.

How to Check If a Volume Is Read-Only or Read-Write

In the "Mounts" section, check both the "Mode" and "RW" fields. If "Mode" is ro or "RW" is false, the mount is read-only. Applications cannot write to the mounted directory.

When running a container, specify read-write or read-only using the -v flag:

docker run -v myvolume:/data:rw container_image

Omitting :rw or :ro defaults to read-write. If the mount is unexpectedly read-only, verify the container was started with :rw and that the underlying filesystem on the host is not mounted read-only.

How to Confirm Volume Persistence Across Container Restarts

To confirm data persists after stopping and removing a container, follow these steps:

  1. Create a named volume: docker volume create mydata.
  2. Start a container using it: docker run -d -v mydata:/data --name test_container alpine sleep 3600.
  3. Write a file: docker exec test_container echo 'hello' > /data/test.txt.
  4. Stop and remove the container: docker stop test_container && docker rm test_container.
  5. Start a new container with the same volume: docker run --rm -v mydata:/data alpine cat /data/test.txt.

If the output is hello, the data persisted. For bind mounts, manually verify the host directory retains files after container removal. Named volumes retain data until explicitly removed with docker volume rm.

How to Debug Missing or Empty Volume Mounts

If a mount appears empty or missing, first confirm the volume is attached using docker inspect. If the mount is listed but empty, check if data was written to the correct path inside the container. Applications may write to a subdirectory not covered by the mount.

For bind mounts, verify the host directory is not empty. If the host path contains data, it will be visible in the container. If the container writes data but it does not appear on the host, the mount may be misconfigured or the wrong path used.

Use mount | grep <container_id> on the host to confirm Docker has set up the mount in the kernel. If no entry appears, the mount failed at runtime. Check docker logs <container_name_or_id> for errors during startup related to volume paths.