- 1 year ago
copy files from docker container to host, or mirror a folder
To copy files from a Docker container to the host, or to mirror a folder in the container to the host, you can use the docker cp
command.
Here's an example of how to copy a file named file.txt
from a running container named mycontainer
to the current directory on the host:
bashdocker cp mycontainer:/path/to/file.txt .
Here's an example of how to mirror a folder named /app
in a running container named mycontainer
to a folder named /myfolder
on the host:
bashdocker cp mycontainer:/app /myfolder
In both examples, you would need to replace mycontainer
with the name or ID of the container that you want to copy files from, and replace the source path (/path/to/file.txt
or /app
) with the path of the file or folder that you want to copy. In the second example, you would also need to replace /myfolder
with the path of the folder on the host where you want to mirror the folder from the container.
Note that if the container is not running, you can still copy files from it using the docker cp
command, but you'll need to specify the container ID or name and the path to the file or folder inside the container. For example:
bashdocker cp mycontainer:/path/to/file.txt .
This would copy file.txt
from the stopped mycontainer
container to the current directory on the host.