Expected behavior
I’m not sure what the proper behavior should be, but I expect using docker-compose backed by docker-machine or Docker for Mac to function the same.
Information
When I delete and recreate a volume on the host, docker-machine sees and mounts the newly re-created directory, but Docker for Mac does not.
I’ve added some steps to reproduce below. Notice how when using docker-machine, the file is accessible when re-created, whereas with Docker for Mac, the file is not available after it’s re-created.
Steps to reproduce the behavior
Create a simple docker-compose.yml file with a volume.
docker-compose.yml
version: '2'
services:
dockertest:
build: .
volumes:
- ./src:/var/www
Dockerfile
FROM ubuntu:14.0
tree
$ tree .
.
├── Dockerfile
├── docker-compose.yml
└── src
└── test.txt
1 directory, 3 files
Using Docker for Mac
Leave this open
$ docker-compose run --rm dockertest bash
root@container:/# cat /var/www/test.txt
hello
… after rm
root@container:/# cat /var/www/test.txt
cat: /var/www/test.txt: No such file or directory
… after mkdir src; echo ‘hello’ > src/test.txt on host
root@container:/# cat /var/www/test.txt
cat: /var/www/test.txt: No such file or directory
In another shell
$ rm -r src
… go to next step in other shell
$ mkdir src; echo ‘hello’ > src/test.txt
Using docker-machine
Leave this open
$ docker-compose run --rm dockertest bash
root@container:/# cat /var/www/test.txt
hello
… after rm
root@container:/# cat /var/www/test.txt
cat: /var/www/test.txt: No such file or directory
… after mkdir src; echo ‘hello’ > src/test.txt on host
root@container:/# cat /var/www/test.txt
hello
In another shell
$ rm -r src
… go to next step in other shell
$ mkdir src; echo ‘hello’ > src/test.txt