RUN mkdir -p /dir1/dir2 && touch /dir1/file1 && touch /dir1/dir2/file2
RUN rm -rf /dir1/file1 && rm -rf /dir1/dir2 && mkdir /dir1/dir2 && touch /dir1/dir2/file3
The third line of the above Dockerfile will generate the following two whiteout files:
- /dir1/.wh.file1: This whiteout file will hide the file "/dir1/file1" created in the second line.
- /dir1/dir2/.wh..wh..opq: This whiteout file will hide all the entries (i.e., "/dir1/dir2/file2") under "/dir1/dir2" created in the second line, but NOT hide "/dir1/dir2/file3" created in the third line.
So when running a container from this image, the hierarchy of "/dir1" in the container's rootfs will be: