如何查找容器已挂载的卷?Docker Compose中Prometheus服务/prometheus挂载来源排查
/prometheus Volume in Your Docker Setup Great question! That unexpected /prometheus mount you're seeing in Portainer isn't a bug—it's actually a behavior baked into the official Prometheus Docker image. Here's how to track down all its details:
Why the Volume Exists (Even Without Defining It)
The official prom/prometheus:latest image includes a VOLUME /prometheus directive in its Dockerfile. Docker automatically creates an anonymous volume for this path whenever you run the container, even if you don't explicitly define it in your docker-compose.yml. This volume stores Prometheus' time-series data, so it persists even if the container is recreated.
Step-by-Step to Find the Volume Details
1. Use Docker CLI to Inspect the Container
Run this command to get full details about your Prometheus container's mounts:
docker inspect <your-prometheus-container-name-or-id>
Look for the Mounts section in the output. It will show:
Type: Should bevolume(anonymous volume)Name: A random alphanumeric ID assigned to the anonymous volumeSource: The actual path on your host machine (usually something like/var/lib/docker/volumes/<volume-id>/_data)Destination:/prometheus(the path inside the container)
2. Check Portainer's Volumes Page
Portainer makes this even easier:
- Navigate to the Volumes tab in Portainer
- Use the search or filter to find volumes associated with your Prometheus container (look for the container name in the "Used By" column)
- Click on the volume to view its details, including the host path and which containers it's mounted to
3. Verify the Compose Configuration
To see the full, expanded configuration Docker Compose uses (including the implicit volume), run:
docker compose config
You'll notice the /prometheus volume is automatically added under the volumes section of your Prometheus service.
Why You Might Not See the Folder
- On the host: The path
/var/lib/docker/volumes/...is owned by therootuser, so you'll need to usesudoto list or access it (e.g.,sudo ls /var/lib/docker/volumes/<volume-id>/_data). - In the container: The
/prometheusfolder definitely exists inside the container—try runningdocker exec -it <container-id> ls /prometheusto confirm it (you might needsudohere too if the container runs as a non-root user).
内容的提问来源于stack exchange,提问作者Eugen Konkov

