1

I know when you create a container the Docker engine adds a thin writable layer on top of the image layers. And all filesystem changes are recorded in that writable layer.

I know I can use the docker diff command to show the changes made in a container's filesystem compared to the base image.

But surprisingly, I cannot see where data are saved in the following use case involving the official MongoDB image:

sh$ sudo docker run -d --name mongo mongo:3.6.10
sh$ sudo docker exec -i mongo mongo << EOF
> db.test.insert({foo:"bar"})
> EOF
MongoDB shell version v3.6.10
MongoDB server version: 3.6.10
WriteResult({ "nInserted" : 1 })
bye

sh$ sudo docker stop mongo
sh$ sudo docker diff mongo
C /root
A /root/.dbshell
C /tmp

/tmp is empty. And /root/.dbshell is just the history file for the mongo client. But I can't see any trace of the data files modified by the Mongo DB server. However, data were definitely stored:

sh$ sudo docker start mongo
sh$ sudo docker exec -i mongo mongo << EOF
> db.test.find()
> EOF
MongoDB shell version v3.6.10
MongoDB server version: 3.6.10
{ "_id" : ObjectId("5c750d4cef8f9635fe459f06"), "foo" : "bar" }
bye

And I can find the data when I manually dump the files:

sh$ sudo docker exec mongo bash -c 'tar c /data/db/collection*' | hexdump -C | grep foo
tar: Removing leading `/' from member names
0000e840  02 66 6f 6f 00 04 00 00  00 62 61 72 00 00 00 00  |.foo.....bar....|

Why can't I find the data files modified by the MongoDB server using docker diff? Did I make some wrong assumption somewhere? Or did I misunderstood something regarding the way docker diff works?

1

I don't know how I missed that, but the mongo image by default stores data in a Docker managed volume, and not in the container writable layer as I assumed it initially.

  • Writing to the container writable image is an anti-pattern. – simbo1905 Mar 2 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.