Copy the directory and the entire subtree connected
I made a mistake that is wanna copy a whole directory using *
in <src>
path, e.g., COPY /path/* /code/
.
Well, I finally find the solution on Stack Overflow [Dockerfile copy keep subdirectory structure]1.
More instruction and rules COPY
obeys [COPY | Docker Documentation]2.
COPY
obeys the following rules:
The <src>
path must be inside the context of the build; you cannot COPY ../something /something
, because the first step of a docker build
is to send the context directory (and subdirectories) to the docker daemon.
If <src>
is a directory, the entire contents of the directory are copied, including filesystem metadata.
Note: The directory itself is not copied, just its contents.
If <src>
is any other kind of file, it is copied individually along with its metadata. In this case, if <dest>
ends with a trailing slash /
, it will be considered a directory and the contents of <src>
will be written at <dest>/base(<src>)
.
If multiple <src>
resources are specified, either directly or due to the use of a wildcard, then <dest>
must be a directory, and it must end with a slash /
.
If <dest>
does not end with a trailing slash, it will be considered a regular file and the contents of <src>
will be written at <dest>
.
If <dest>
doesn’t exist, it is created along with all missing directories in its path.
References
- https://stackoverflow.com/a/30220096.
- https://docs.docker.com/engine/reference/builder/#copy.