According to Docker documentation search for: "Leverage build cache", there is checksum calculated on the directory - please see the article for details.
What I will suggest is a multistage build.
If we have static content of directory we could create container/image with its content. Then instead of using Docker copy, we could use FROM as a build stage and copy that directory into a new layer, which in fact will reuse that layer. That is based on a fact that we don't operate on a directory (when a file could get a changed attribute like last accessed time).
Base Dockerfile
FROM alpine:latest
COPY /myDirectory .
Then you could tag this container as storage-base
Then you could tag this container as storage-base O MultiStage Dockerfile
FROM storage-base AS storage
FROM alpine:latest
RUN a command
WORKDIR /root/
COPY --from=storage /myDirectory .
Please check more references here: Docker Multistage Build
Edit
- the image/container created in step 1 shall be only recreated when directory content will change (by a trigger that knows that the data changed), so that means it will not be created on every build.
- then we use the image that was created once (and re-use that layer)
I just created a simple example to help express my idea - Git repo - run build-docker.sh script
I found that on reboot Docker is re-creating cache instead of reusing, but it takes just a few minutes and it is not critical.