We have a build pipeline that first does a docker build using a dockerfile. That dockerfile has a number of COPY commands. We also have a later step that does a docker run, with 'cp' command, as follows:
docker run --volume /hostDirA:/containerDirB --workdir /folderB dockerRepo:somebuildnum cp -R /hostDirC/. /containerDirB
First, before the main point, it is my understanding that the cp command is copying from one folder to another, both folders on the container. Is that a correct understanding?
Second, why would a cp be done in this way in the docker run when COPY is already being done in the docker build via the dockerfile? Are there valid reasons why we wouldn't move this cp to be inside the dockerfile?
COPY
is appropriate when you're creating a new layer.cp
is appropriate when you're copying content out of the container onto a volume. To be clear,docker run cp
does not create a new layer. Thus, it is not a substitute for aCOPY
directive. – FantoccinicontainerDirB
has a symlink in its path that should make it land on a volume, that too would make this make more sense. – Fantoccinicp
having occurred, how and when is it invoked, does it actually work as intended? -- which is not something suited to our format. – Fantoccinicp
source folder is something from the image (not a host directory), and its destination folder is the second--volume
directory, then this seems like it's trying to copy data out of an image build on to the host. – Rotherham