ScanSkill

docker cp

The command docker cp is used to copy files/folders between a container and the host.

Syntax

$ docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
# OR
$ docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

Here, - specified for either SRC_PATH or DEST_PATH enables to stream tar archive from STDIN or to STDOUT. And SRC_PATH or DEST_PATH can be a file or directory.

Options;

  • --archive, -a → Archive mode — copy all userid or groupid (uid/gid) information
  • --follow-link, -L → Follow the symbol link in SRC_PATH

Examples

  • Copy files from a container to host(local)
$ docker cp cloudyfox_web:/index.html index.html
  • Copy files from local to the container
$ docker cp ./index.html cloudyfox_web:/index.html
  • Copy a file from the container to stdout
$ docker cp CONTAINER:/var/logs/app.log - | tar x -O | grep "ERROR"

Note: Please note cp command produces a tar stream.