Reputation: 6076
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?
Upvotes: 7
Views: 6986
Reputation: 3424
Without knowing what the files are for, we can only take wild guesses.
Volumes are used for data persistence, whereas COPY is used for data that is needed in running the process, but may be destroyed.
One possible valid scenario for why data is copied into the volume instead of using the COPY command is that persistent data needs to be initialized and they don't want that initialization data to add bloat to the container image. Like I said, it's just a wild guess.
Another guess is that the Dockerfile is shared between developers and the initialization data between groups may vary, so one set of developers might copy different data into the volume.
Whatever the data is, if you shut down and remove the container, data created via COPY
just vanishes with the container, but data moved into the volume via cp
on the host stays in the directory that was mounted. That data may have changed while the container was running from what was originally placed in it, but it doesn't reset when you remove the container and spawn a new container from the image.
You should ask the developer what all the files are for, and whether the files need to persist or whether they can just be "ephemeral". This will probably answer your questions as to why they are copied the way they are.
Upvotes: 2