Skip to content

overlay2: layers and copy-on-write

Select an icon to see what it is.

Step 6 of 6

docker diff lists the changes

docker diff reads the upper layer and prints A for added, C for changed and D for deleted paths. Parent directories of a change also show as C, and the real output has more entries than shown here. Removing the container deletes the upper layer, and the image stays the same.

$ docker diff web
PrevNext

GET /v1.45/containers/f1a2b3c4d5e6/changes

[
{
"Path": "/etc"
"Kind": 0
}
{
"Path": "/etc/nginx"
"Kind": 0
}
{
"Path": "/etc/nginx/nginx.conf"
"Kind": 0
}
{
"Path": "/hello.txt"
"Kind": 1
}
{
"Path": "/usr"
"Kind": 0
}
{
"Path": "/usr/share"
"Kind": 0
}
{
"Path": "/usr/share/nginx"
"Kind": 0
}
{
"Path": "/usr/share/nginx/html"
"Kind": 0
}
{
"Path": "/usr/share/nginx/html/50x.html"
"Kind": 2
}
]

Try it yourself

Change a container's files and read the layers on the host.

$ docker run -d --name web nginx
$ docker exec web sh -c 'echo hi > /hello.txt && rm /usr/share/nginx/html/50x.html'
$ docker diff web
$ docker inspect --format '{{.GraphDriver.Data.UpperDir}}' web
$ sudo ls -l $(docker inspect --format '{{.GraphDriver.Data.UpperDir}}' web)/usr/share/nginx/html
$ docker rm -f web

Quiz

1. Where do a container's new files go?
2. What is copy-on-write?
3. How is a deleted image file recorded?