How to mirror a container directory on the host?
All I want is to be able to read a directory of my container from my host machine. I.e., a symlink from my host machine to the container's directory, and I don't require anything more than read permissions.
I have tried many different methods:
services:
django:
volumes:
- /tmp/docker-django-packages:/usr/local/lib/python3.12/site-packages
Problem: /tmp/docker-django-packages
is not created if it doesn't exist, but there is no docker error, however no python packages can be resolved by the container's python process. If I manually make /tmp/docker-django-packages
on the host, then I still get the same error.
services:
django:
volumes:
- type: bind
source: /tmp/docker-django-packages
target: /usr/local/lib/python3.11/site-packages
bind:
create_host_path: true
Problem: /tmp/docker-django-packages
is not created. If I make it manually, it is not populated. The container behaviour is not affected at all.
services:
django:
volumes:
- docker-django-packages:/usr/local/lib/python3.11/site-packages
volumes:
docker-django-packages:
driver: local
driver_opts:
type: none
o: bind
device: "/tmp/docker-django-packages"
Problem: host directory not created if it doesn't exist, not populated if it already exists, and the container functions as normal
services:
django:
volumes:
- type: volume
source: docker-django-packages
target: /usr/local/lib/python3.11/site-packages
volumes:
docker-django-packages:
driver: local
driver_opts:
type: none
o: bind
device: "/tmp/docker-django-packages"
Problem: host directory not created, nor populated, container yet again functions as if these lines weren't in the compose file at all
services:
django:
volumes:
- type: bind
source: docker-django-packages
target: /usr/local/lib/python3.11/site-packages
volumes:
docker-django-packages:
driver: local
driver_opts:
type: none
o: bind
device: "/tmp/docker-django-packages"
Problem: nothing changes on the host machine (no new directory, no new contents if I make it manually), but the container python process can no longer find. Also seems to require making the service privileged
for the first run. Also seems to do some kind of caching, if I remove the privileged
permission for subsequent runs, the container starts but I just get python import errors.
So what am I actually meant to do so that I can have read access to a container's folder from my host machine?