Is there a way to use docker cp so that it exclude files/folders from .dockerignore the way COPY in dockerfile does?
Is there a way to use docker cp so that it exclude files/folders from .dockerignore the way COPY in dockerfile does?
No, there is no way (docker cp). A hacky workaround is to execute a script, that makes symbolic links of the files you need. After that you copy these files. But thats not how docker should be used.
If you want change the code inside your container, then you have to build a new image.
If want you to change configurations then use other mechanism like volumes or environments-variables.
And if you want to pull out some generated files, then use volumes instead.
Side node: I dont know what you like to do, but keep in mind that docker is not a virtual machine. See https://devopscon.io/blog/docker/docker-vs-virtual-machine-where-are-the-differences/