Docker - eekbot/public GitHub Wiki
Here's a link to a free course I took:
https://www.youtube.com/watch?v=RqTEHSBrYFw&t=8336s
https://github.com/sidpalas/devops-directive-docker-course
I will be taking some excerpts from there.
# How to View Data Inside Mounted Volumes on Mac We can now create a new container and mount the existing volume to confirm the file persisted: # Create a new container and mount the volume into the container filesystem docker run -it --rm --mount source=my-volume,destination=/my-data/ ubuntu:22.04 cat my-data/hello.txt # This time it succeeds! exit Where is this data located? On linux it would be at /var/lib/docker/volumes... but remember, on docker desktop, Docker runs a linux virtual machine. One way we can view the filesystem of that VM is to use a [container image](https://hub.docker.com/r/justincormack/nsenter1) created by justincormat that allows us to create a container within the namespace of PID 1. This effectively gives us a container with root access in that VM. *NOTE: Generally you should be careful running containers in privileged mode with access to the host system in this way. Only do it if you have a specific reason to do so and you trust the container image.* # Create a container that can access the Docker Linux VM # Pinning to the image hash ensures it is this SPECIFIC image and not an updated one helps minimize the potential of a supply chain attack docker run -it --rm --privileged --pid=host justincormack/nsenter1@sha256:5af0be5e42ebd55eea2c593e4622f810065c3f45bb805eaacf43f08f3d06ffd8 # Navigate to the volume inside the VM at: ls /var/lib/docker/volumes/my-volume/_data cat /var/lib/docker/volumes/my-volume/_data/hello.txt # Woohoo! we found our data! This approach can then be used to mount a volume at the known path where a program persists its data: # Create a container from the postgres container image and mount its known storage path into a volume named pgdata docker run -it --rm -v pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=foobarbaz postgres:1