Originally created by: dcendents
When I re-create a container after adding a volume, I expect it to be mounted and the data copied inside or not created at all.
Output of docker-compose version
docker-compose version 1.23.2, build 1110ad01
docker-py version: 3.6.0
CPython version: 3.6.7
OpenSSL version: OpenSSL 1.1.0f 25 May 2017
Output of docker version
Client:
Version: 18.06.1-ce
API version: 1.38
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:23:03 2018
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:25:29 2018
OS/Arch: linux/amd64
Experimental: false
Output of docker-compose config
See https://github.com/dcendents/docker-compose-volumes
docker-compose -f docker-compose.yml up -d
Creating network "docker-compose-volumes_default" with the default driver
Creating dc-volume ... done
docker volume ls
DRIVER VOLUME NAME
local c4ef0cbfbb4df01a1785ed753c3ecb7f675a0ef28d420b6993b50f662f9d5d2c
docker inspect --format='{{range .Mounts}}{{.Name}} {{end}}' dc-volume
c4ef0cbfbb4df01a1785ed753c3ecb7f675a0ef28d420b6993b50f662f9d5d2c
docker-compose -f docker-compose.yml -f docker-compose.with_volume.yml up -d
Creating volume "docker-compose-volumes_volume_name" with default driver
Recreating dc-volume ... done
docker volume ls
DRIVER VOLUME NAME
local c4ef0cbfbb4df01a1785ed753c3ecb7f675a0ef28d420b6993b50f662f9d5d2c
local docker-compose-volumes_volume_name
docker inspect --format='{{range .Mounts}}{{.Name}} {{end}}' dc-volume
c4ef0cbfbb4df01a1785ed753c3ecb7f675a0ef28d420b6993b50f662f9d5d2c
The new volume has been created but is not mounted on the container, if I do a down and up again I will actually lose the content which led me to believe was in my volume.
Based on https://docs.docker.com/compose/overview/#preserve-volume-data-when-containers-are-created this behaviour might be by design.
In an ideal world, the new volume would be used and it's data initialized with what was previously in the anon volume.
Otherwise it should not create the new volume and display a warning instead. At least I would not think the volume is now being used. I'm not in the habit of doing docker inspect and review everything. If my docker-compose.yml file mentions a volume and docker volume ls lists it, I assume it is mounted as intended.
Thanks,