To all the beginners: don’t make this a habit. A workflow relying on docker cp sounds wrong on so many levels…
Valid usecases for docker cp are:
– when you need a config file to start the container, which does not get generated/copied when you bind a host folder into the target. Copy the files to the host, recreate the container and this time use volumes to map the config file back into the container.
– when you want to export one shot debug or logging information from the container to the host (if this happes regularly: use volumes and/or log management!).
– when you forget to mount a volume to persist stateful data on the host, and now you want to “export” the data to the host, so you can delete the container and re-create it with a bind-mount to the host folder you copied the files to.
#3 typical happens to beginners and allows to fix a wrong doing, 2 usualy happes during troubleshootings, #1 can be reoccurring, depening on the images you us.