Problem: when I use docker-compose up --force-recreate
and a volume has changed in the docker-compose.yml file, I get a warning saying that the newly created container still uses the old volume. This makes it quite complex to use the tool reliably in CD environment, since some changes wouldn't be actually be propagated to production (I'd prefer the tool to actually fail rather than issuing a warning).
I would expect that either docker-compose starts a new container with a new volume, or at least fails with an error
Example of the issue (tested on Ubuntu 16.04, docker-engine 1.13.1, docker-compose 1.11.0):
docker-compose.yml
cassandra:
image: cassandra:2.1
alan@alan-virtualbox-mate:~/test-docker-compose-issue$ docker-compose up -d
Creating testdockercomposeissue_cassandra_1
alan@alan-virtualbox-mate:~/test-docker-compose-issue$
docker-compose.yml
cassandra:
image: cassandra:2.1
volumes:
- /home/alan/test-docker-compose-issue/data:/var/lib/cassandra
alan@alan-virtualbox-mate:~/test-docker-compose-issue$ docker-compose up --force-recreate -d
Recreating testdockercomposeissue_cassandra_1
WARNING: Service "cassandra" is using volume "/var/lib/cassandra" from the previous container. Host mapping "/home/alan/test-docker-compose-issue/data" has no effect. Remove the existing containers (with `docker-compose rm cassandra`) to use the host volume mapping.
alan@alan-virtualbox-mate:~/test-docker-compose-issue$
Possibly related: #2481 and #2609 (I think it should have been solved, but I still get the behaviour).
You might want to try docker-compose down -v -f
before the up
command.
I'm experiencing this bug too on Docker version 17.04.0-ce, build 4845c56.
Same here, docker-compose version 1.16.1, build 6d1ac21
Any update on this?
Sorry folks, but this is working as intended. As @Umkus points out, the way to proceed if you do not want to preserve data from previous runs is to run docker-compose down -v -f
@shin- how do you feel about adding a flag to support this use case?
The problem with doing a docker-compose down && docker-compose up
is that it stops all the containers defined in the docker-compose.yml
. By contrast, a docker-compose --recreate-even-if-it-removes-volumes
would only need to recreate the containers whose mounts have changed.
docker-compose up --renew-anon-volumes
might be what you are looking for.
-V, --renew-anon-volumes Recreate anonymous volumes instead of retrieving
data from the previous containers.
Most helpful comment
You might want to try
docker-compose down -v -f
before theup
command.