
If you have files in your docker container that you want to get into your host/local device, you can achieve it using the docker cp command.
Example:Inside the docker container I have a file 20220901.log under the root directory, I want to get it to my host system,.
# pwd
/root
# ls
20220901.log
Copy file from Docker Container
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1d2b384f31de alpine "/bin/sh" 6 minutes ago Exited (0) 6 minutes ago intelligent_noether
% docker cp 1d2b384f31de:/root/20220901.log
Note: You might get operation not permitted if you try to copy the file to the host directory where you do not have permission to write.
Also, if a path or file does not exist on the docker container you will get an error: No such container:path: or if the host path is invalid: invalid output path: directory does not exist
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!