Is there a way to use docker cp
so that it exclude files/folders from .dockerignore
the way COPY in dockerfile does?
The docker cp utility copies the contents of SRC_PATH to the DEST_PATH . You can copy from the container's file system to the local machine or the reverse, from the local filesystem to the container. If - is specified for either the SRC_PATH or DEST_PATH , you can also stream a tar archive from STDIN or to STDOUT .
dockerignore file is on the root directory of your context, it will ignore it if it is somewhere in the subfolder.
The documentation says that yes it can. You can even use the . dockerignore file to exclude the Dockerfile and . dockerignore files.
dockerignore doesn't list some file that is . gitignored , then our build context on the developer's machine will include this file whereas a build context in the Continuous Integration environment won't (as it only works on files present in the git repository).
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With