Skip to content

Instantly share code, notes, and snippets.

@kuznero
Last active June 12, 2017 18:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuznero/dcc2c427d76a1e5f7e2190a4f5e23b7d to your computer and use it in GitHub Desktop.
Save kuznero/dcc2c427d76a1e5f7e2190a4f5e23b7d to your computer and use it in GitHub Desktop.

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:

FROM mono
ADD . /src
# RUN cd /src &&
#     chmod +x ./build.sh &&
#     ./build.sh &&
#     mkdir /app &&
#     cp /src/build/app/* /app &&
#     rm -rf /src
RUN cd /src &&
    chmod +x ./build.sh &&
    ./build.sh &&
    mkdir /app &&
    cp /src/build/app/* /app &&
    find /src -type f | xargs -L1 rm -f
WORKDIR /app
CMD [ "mono", "Service.exe" ]

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

@jczinger
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment