Workaround for `Unexpected file permission error in container`

Posted in category tips on 2016-07-20
Tags: tips, docker

Due to issue registered on docker repository on github “unexpected file permission error in container”, #783 it is impossible to run rm -rf /somefolder for a folder that was created with ADD or COPY instructions of Dockerfile.

As a workaround to this it is possible to remove individual files one-by-one in case when this operation runs on the same layer: find /src -type f | xargs -L1 rm -f

Here is an example of Dockerfile (commented out lines is how you would normally do it):

This will leave the folder in place but there will be an option to flatten your docker image.

My docker version looks like this (hoping it will be fixed in the coming versions of docker):