Reputation: 2403
Perhaps I'm missing something stupid but there is something I don't understand.
If I do docker run -d --name test -v ~/test-log:/var/log/nginx -v ~/test-config:/etc/nginx/conf.d nginx:latest
I've got
ls -l ~/test-log
total 0
-rw-r--r-- 1 root root 0 Sep 1 11:17 access.log
-rw-r--r-- 1 root root 0 Sep 1 11:17 error.log
But
ls -l ~/test-config
total 0
However without any mounts /etc/nginx/conf.d
is not empty
docker run --rm --name test2 nginx:latest ls -l /etc/nginx/conf.d
total 4
-rw-r--r-- 1 root root 1093 Aug 11 14:50 default.conf
So why files in /var/log/nginx
are well present in ~/test-log
while ~/test-config
remains empty and moreover /etc/nginx/conf.d
becomes empty ?
What am I missing ?
Upvotes: 1
Views: 339
Reputation: 264236
Volumes mount files/directories from the source over whatever exists inside the image at that location. You no longer see the image contents when a mount replaces access to that directory, same a mounting a filesystem other ways in Linux.
Named volumes in Linux are a semi exception because docker initializes the contents of a named volume with the image directory contents. This does not apply to host volumes like you are using.
Once the volume is mounted, files are created/modified/deleted by the application running inside the container. In this case, that app creates logs, but it does not write it's own configuration files.
Upvotes: 1