Docker Container Copy

We might sometimes require copying files from a local machine to a container or from a container to the local machine. So container cp command is used to copy files/folders between a container and the local filesystem and vice versa.

Syntax

$docker cp <src-path> <container>:<dest-path>

Examples

learning-ocean:~ gaurav$ docker container run -itd ubuntu:14.04 bash
ec9ac9fe5ee50dd0349878ca87ed8c115ee5565334626bc2885acbc7e1586d7c
learning-ocean:~ gaurav$ docker container ls
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS               NAMES
ec9ac9fe5ee5   ubuntu:14.04   "bash"                   4 seconds ago   Up 2 seconds                       gallant_curie
learning-ocean:~ gaurav$ docker container cp test  ec9ac9fe5ee5:/tmp/

Verifying the same-

learning-ocean:~ gaurav$ docker container attach ec9
root@ec9ac9fe5ee5:/# cd /tmp
root@ec9ac9fe5ee5:/tmp# ls
test
root@ec9ac9fe5ee5:/tmp#

You can Copy a from container to host machine using below command

$ docker container cp containerId:/path/in/container /path/in/hostmachine