How to map a docker containers directory to the host with docker-compose?
Reading from: Dockers Volume Page
Volumes have several advantages over bind mounts:
New volumes can have their content pre-populated by a container.
So a simple docker-compose (inside a folder called nginx):
version: "3.7"
volumes:
xmpl:
services:
testnginx:
image: nginx:stable
volumes:
- xmpl:/etc/nginx
Will yield all the files on the host system via:
$ docker-compose up
$ docker inspect nginx_xmpl
...
"Mountpoint": "/var/lib/docker/volumes/nginx_xmpl/_data"
And you can then view the files on the host:
# ls /var/lib/docker/volumes/nginx_xmpl/_data
conf.d fastcgi_params koi-utf koi-win
mime.types modules nginx.conf scgi_params
uwsgi_params win-utf
And finally to use it from ./config:
# ln -s /var/lib/docker/volumes/nginx_xmpl/_data ./config
# ls config
conf.d fastcgi_params koi-utf koi-win
mime.types modules nginx.conf scgi_params
uwsgi_params win-utf