How to Use Docker Cp to Copy Files Between Host and Containers

Aug 27, 2021, 7:30 am EDT | 4 min read Need to get some files into or out of a Docker container? The docker cp command lets you copy between host and container filesystems so you can add config details, create backups, and restore existing data. Basic Syntax docker cp accepts source and destination paths as its two arguments: docker cp example.txt my-container:/example.txt Here example.txt is being copied from your working directory to /example.txt in the my-container container. You could reverse the two arguments to copy /example.txt out of the container and into your working directory. The argument referencing the container path needs to be prefixed with a container ID or name followed by a colon (:). You can find the ID or name of a running container with docker ps. Each docker cp command needs one local filesystem path and one container path – you can’t directly copy between two containers. Use a multi-step procedure if you need to do this, copying first from the source container to your filesystem, then from the new local pa… Click below to read the full story from How To Geek
Read More