Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Locating Docker Container Storage Paths on Linux

Tech 3

On Linux hosts, Docker persists container data within the host filesystem under the daemon's root directory, typically /var/lib/docker. This location houses image layers, container metadata, volumes, and network configurations.

To determine the current storage location and disk utilization:

df -h $(docker info -f '{{ .DockerRootDir }}')

Or inspect the directory contetns directly:

ls -la /var/lib/docker/

Within this directory, active containers store their writable layer contents in subdirectories managed by the storage driver (such as overlay2 or devicemapper). To identify a specific container's filesystem path:

docker inspect --format='{{ .GraphDriver.Data.MergedDir }}' <container_name>

For containers utilizing bind mounts or named volumes, locate the host-side source paths with:

docker inspect --format='{{range .Mounts}}{{.Type}}: {{.Source}} -> {{.Destination}}{{"\n"}}{{end}}' <container_name>

Practical demonstration:

# Launch a sample workload with volume attachment
docker run -d \
  --name demo-app \
  -v /opt/data:/app/data \
  -p 8080:80 \
  httpd:alpine

# Retrieve the container's root filesystem location
docker inspect --format='{{ .GraphDriver.Data.MergedDir }}' demo-app

# List volume mount mappings
docker inspect --format='{{range .Mounts}}Host: {{.Source}}, Container: {{.Destination}}{{end}}' demo-app

To examine the global volume storage directory:

docker volume inspect --format='{{ .Mountpoint }}' <volume_name>

This information assists in troubleshooting storage issues, performing manual backups of container data, or cleaning up orphaned layers when standard pruning commands prove insufficient.

Related Articles

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.