Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run docker cp excluding files from .dockerignore

Tags:

docker

Is there a way to use docker cp so that it exclude files/folders from .dockerignore the way COPY in dockerfile does?

like image 224
Quba Avatar asked Aug 08 '17 06:08

Quba


People also ask

What does Docker CP command do?

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 .

Where should Dockerignore file be?

dockerignore file is on the root directory of your context, it will ignore it if it is somewhere in the subfolder.

Should I put Dockerfile in Dockerignore?

The documentation says that yes it can. You can even use the . dockerignore file to exclude the Dockerfile and . dockerignore files.

Does Dockerignore use Gitignore?

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).


1 Answers

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/

like image 115
akop Avatar answered Oct 23 '22 15:10

akop