For the sake of simplicity, let’s say I have the following structure in the source image:
files/
folder1/
file1
file2
folder2/
file1
file2
I want to have a result where only the directory structure is copied to my other image during build. The result should therefore look like this:
files/
folder1/
folder2/
How can this be achieved?
Background: You might ask why I want to do this. Well, in reality the directory structure is much more complex and I need to maintain consistency between both source and destination image. And as there are significant amounts of data in the source image I cannot simply copy over everything and then remove the files (as this would take a lot of time).
2
Answers
Actually Pádraig Galvin and KamilCuk pointed to what I wanted to achieve. This how I did it in the end:
It gives the same structure in "some_image" and "destination":
Dynamic programming:
So something along:
The specifics, programming language, the representation of "the list of directories", quoting and anything may change – the algorithm stays.
You can do it better by zero separated list:
And you can prepend docker to it:
Or you could save the list to a file and then use it in dockerfile: