Map Docker Volume to Host Filepath

  docker, logging, python


I would like to have logs from a Python app running on a Docker container show up at spot D in the below diagram. How do I do this?


I am aware that this seems to point directly at using bind mounts, but my understanding of Dockers documentation is that they strongly suggest using volumes where possible, and I would like to have this be OS agnostic (developing on macOS, planning to run on a Rasberry Pi, potentially move to AWS/some other cloud service at some point) .

Currently, I’ll start my container with the following command:

$ docker run -d --mount type=volume,source=app-logs,target=/app/logs super-cool-image-name

Once it is running, I’ll inspect the volume:

$ docker volume inspect app-logs
        "CreatedAt": "2021-12-01T22:31:26Z",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/app-logs/_data",
        "Name": "app-logs",
        "Options": null,
        "Scope": "local"

My understanding (correct me if I’m wrong) is that the above Mountpoint is at point C in the below diagram. If I then run the following (taken from this SO question):

$ docker run -it --privileged --pid=host debian nsenter -t 1 -a bash

I can go to the directory specified in the above Mountpoint and find the log file I’m looking for:

bash-5.0# cd /var/lib/docker/volumes/app-logs/_data/
bash-5.0# ls

enter image description here

Question(s) (again)

  • How can I "map" point C to point D in order to view the log file?
  • Would doing this be bad practice, and should I just get used to going through the VM when I want to view logs?

Source: Python Questions