Repository navigation
Description
Hi everyone,
Im not sure if this is a docker, docker-compose or a "me" bug. But Im not getting my head around this for several hours.
My simple docker-compose.yml
version: "2"
services:
app:
image: nginx:latest
volumes_from:
- storage
storage:
image: ubuntu:latest
volumes:
- /var/data
I bootstrap it with $ docker-compose up -d.
Now I jump into "app" via docker exec -it docker_app_1 bash and add a test file within my new created volume.
root@8f5f850c30c7:/# touch /var/data/test
root@8f5f850c30c7:/# ls /var/data
test
Seems to work. Shutdown via $ docker-compose stop. Now I add a second volume to my storage container:
version: "2"
services:
app:
image: nginx:latest
volumes_from:
- storage
storage:
image: ubuntu:latest
volumes:
- /var/data
- /my/host/folder:/var/data2
This time this volume is backed by a host directory. Rerun:
$ docker-compose up -d
Recreating docker_storage_1
Recreating docker_app_1
Okay so far. Recreated my storage container, but should preserve existing volumes (docs). Lets check this:
$ docker exec -it docker_app_1 bash
root@8f5f850c30c7:/# ls /var/data
Oh my data is gone, but why? This is not the only time my data gots "lost" the last days.
Its not 100% clear when this will happen. Simple running $ docker-compose up -d --force-recreate twice kills my data also. After the first launch my data is still there and after the second one its lost. Is this expected behavior? Recreate process seems to be broken in compose 1.6.0 :(
This happens on my local environment (OS X, docker 1.10.0, compose 1.6.0) and on my ubuntu-backed vServer (docker 1.10.1, compose 1.6.0).
Thanks for any advice
System:
$ docker-compose -v
docker-compose version 1.6.0, build d99cad6
$ docker version
Client:
Version: 1.10.0
API version: 1.22
Go version: go1.5.3
Git commit: 590d5108
Built: Thu Feb 4 18:18:11 2016
OS/Arch: darwin/amd64
Server:
Version: 1.10.0
API version: 1.22
Go version: go1.5.3
Git commit: 590d5108
Built: Thu Feb 4 19:55:25 2016
OS/Arch: linux/amd64
Activity
dmp1ce commentedon Feb 14, 2016
I'm experiencing something similar here with
--force-recreate: MariaDB/mariadb-docker#42[-]DOC: Unexpected data loss when changing docker-compose.yml[/-][+]DOC: Unexpected data loss when recreate containers[/+]otbe commentedon Feb 14, 2016
Changed title and text. Seems to be recreate related...
dmp1ce commentedon Feb 14, 2016
I hope this one gets sorted out soon. Unexpected data loss is not fun.
dnephin commentedon Feb 14, 2016
I see what's happening.
We made this change (#2706) in 1.6.0. If a volume doesn't have a name it should be a "host volume" so not copied over. The problem is, docker engine seems to returning container volumes without including the name.
The first time a volume is copied over the name exists, so the copy works just fine. The second time, the inspect looks like this:
{ "Propagation": "rprivate", "RW": true, "Mode": "rw", "Destination": "/var/data", "Source": "/var/lib/docker/volumes/b449ba245cef3a3f509dc41e59ba6b2e6b094702e3498077c4acaffc22f6a31b/_data" },No name! but if I inspect the volume:
Clearly there is a name.
So there is an issue here, I think it might be a bug in the docker engine, at the very least there's a integration issue between compose and the engine. There may be a better way for us to re-attach the volume so that it continues to be copied over.
dnephin commentedon Feb 14, 2016
I'll prepare a PR for this on Tuesday, but I think this patch might fix it (still need to run the test suite against it):
dmp1ce commentedon Feb 14, 2016
Thank you @dnephin
That patch seems to fix the issues I had with
--force-recreatewhen using mariadb.dnephin commentedon Feb 14, 2016
The good news is that the data isn't gone, the volume is just detached from the container. A workaround to restore the data would be to do this:
The difficult part is finding the volume id.
docker volume lslists them. If you only have a few it should be easy to find. If you have many, you might need to run afindover the files in/var/lib/docker/volumes/.dmp1ce commentedon Feb 14, 2016
Does this effect
docker-compose run? I'm trying to do a simple test to see attached volume withdocker-compose runand it isn't working for me.docker-compose runshould attach to previous volumes, shouldn't it?$ cat docker-compose.yml ubuntu: image: ubuntu volumes: - /data command: bash -c "date >> /data/testing && ls -alh /data" $ docker-compose up Creating mariadbinit_ubuntu_1 Attaching to mariadbinit_ubuntu_1 ubuntu_1 | total 8.0K ubuntu_1 | drwxr-xr-x 2 root root 4.0K Feb 14 19:44 . ubuntu_1 | drwxr-xr-x 22 root root 273 Feb 14 19:44 .. ubuntu_1 | -rw-r--r-- 1 root root 29 Feb 14 19:44 testing mariadbinit_ubuntu_1 exited with code 0 $ docker-compose run --rm ubuntu bash -c "sleep 1 && ls -alh /data" total 4.0K drwxr-xr-x 2 root root 4.0K Feb 14 19:45 . drwxr-xr-x 22 root root 273 Feb 14 19:45 ..Edit: Apparently not. My test doesn't work for docker-compose 1.4.0 either.
dmp1ce commentedon Feb 14, 2016
Here is a simple test for anyone who wants to manually reproduce this:
$ cat docker-compose.yml ubuntu: image: ubuntu volumes: - /data command: bash -c "date >> /data/testing && ls -alh /data && cat /data/testing" $ docker-compose up --force-recreate $ docker-compose up --force-recreateYou should see dates concatenated over and over again. With this issue the dates will start over after the second command.
dnephin commentedon Feb 14, 2016
No, volumes are not copied on
run, only withup. Run should still use thevolumes_fromof another container, if one is defined.mc0e commentedon Feb 22, 2016
is this related to #1576 ?
mc0e commentedon Feb 22, 2016
The workaround in #2912 (comment) is useful, but also seems to be inviting trouble. If that data volume is not set up properly, it could wind up getting deleted. For all that docker is not good at doing that automatically (still the case? for how long?), it's likely to be part of a manual cleanup effort.
Better to move the data to a more permanent external volume location.
shin- commentedon Feb 22, 2016
It is being fixed in the upcoming release, see #2934.