Question about behavior of COPY in Dockerfile. An AI is gaslighting me, unsure which

In a Dockerfile does A:
COPY --from=deps /app/node_modules/ws ./node_modules/ws
COPY --from=deps /app/node_modules/ws ./node_modules/ws
produces the same behavior as this B:
COPY --from=deps /app/node_modules/ws ./node_modules/
COPY --from=deps /app/node_modules/ws ./node_modules/
??? Both Gpt4-o and Gemini insist they are equivalent, Claude 3.7 disagrees From the docs https://docs.docker.com/reference/dockerfile/#destination-1
Trailing slashes are significant. For example, COPY test.txt /abs creates a file at /abs, whereas COPY test.txt /abs/ creates /abs/test.txt.
I believe A and B are equivalent, but just wanted to fact check. I'm confused now.
Docker Documentation
Dockerfile reference
Find all the available commands you can use in a Dockerfile and learn how to use them, including COPY, ARG, ENTRYPOINT, and more.
1 Reply
Rusty
Rusty•3d ago
So, there is a difference; what is happening you are choosing an item in your case the ws directory to copy INTO the node_modules directory, but not the folder itself. So you want to use command A in this situation, otherwise the your node_modules folder will have the contents of the folder ws instead of having the content of ws inside a module folder named ws which is a child of node_modules. Hope this make sense 😅

Did you find this page helpful?