How to Copy files from Docker Container to Host System

Copy Files from Docker Container to Host

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.


Inside the docker container I have a file 20220901.log under the root directory, I want to get it to my host system,.

# pwd

# ls

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


Have Questions? Post them here!

Top Hashtags: