Let's first see the definition/purpose of both of them :
WORKDIR : This instruction is used to set the working directory in the container.
COPY : This instruction is used to copy any files from the host onto the container.
The reason why these instructions should be used are :
- Using WORKDIR gives clarity and reliability.
- Using RUN cd … && do-something instructions instead is tougher as they are hard to read & maintain & troubleshoot.
It would be better if you understood these instructions and made proper use of them as these are part of the best docker practices, so keep them in mind.
Hope this helped :)
If you want to know more about how to make really effective docker files and overall become better at docker make sure to check out docker training course.