docker container cp command. This utility works in both directions:
- Host → Container
- Container → Host
- A container named
webapprunning on your Docker host - A file on the host at
/tmp/web.conf
Copying from Host to Container
Syntax
Example
- Source (host):
/tmp/web.conf - Destination (container):
webapp:/etc/web.conf
If you specify a directory as the destination, ensure that directory already exists inside the container.
Copying from Container to Host
Simply reverse the source and destination:- Source (container):
webapp:/etc/web.conf - Destination (host):
/tmp/web.conf
Any existing file at the destination path will be overwritten without confirmation.
Copying Entire Directories
To copy a complete directory (including its contents), include trailing slashes:config folder into /etc/config inside the webapp container. Ensure /etc/config exists in the container before running the command.