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.
Command Reference
| Direction | Command Syntax | Description |
|---|---|---|
| Host → Container | docker container cp /path/on/host container_name:/path/in/container | Copy files or directories into container |
| Container → Host | docker container cp container_name:/path/in/container /path/on/host | Copy files or directories to host |