As part of my quest to completely understand how docker deals with volumes under the hood (followup from my previous post), I'm curious about how running docker-compose stop deals with volumes.
There are two possibilities that I suppose may happen:
- Volumes are unmounted after running
docker-compose stopand then mounted again in lexographic order when runningdocker-compose start. - Volumes stay mounted until the container is removed using
docker-compose rmor a similar command.
I was curious as even restarting a stopped container will create an empty directory in my host folder. I have the following in my docker-compose.yml:
volumes:
- .:/var/www/app
- my_modules:/var/www/app/node_modules
So, from my understanding of the answer in the linked post above, the empty directory is created because of the following:
- Bind mount happens first (lexographic order), overwrites everything in
/var/www/app - Docker will try to mount
node_modules, but since the directory no longer exists in the container (overwritten), it willmkdir node_modulesto have a directory to mount the named volume. - Since the bind mount already exists when the
mkdirhappens, I see a new, emptynode_modulesfolder in my host.
This makes complete sense if the volumes are being mounted, but if 2) is true and they stay mounted even after running docker-compose stop, why would I still be seeing an empty directory being created in my host? I remove node-modules from my host in between the stop and up command for reproducing this behavior.