Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy file from remote docker container

Tags:

docker

ssh

I have a running container on a remote machine. I am connected to the machine via ssh. Now i would like to download a certain file from the container. Can somebody give me some tips how to achieve that ? Thanks. 🙂

like image 697
Andrej Hucko Avatar asked May 07 '18 15:05

Andrej Hucko


People also ask

How do I copy a file from Docker container to remote host?

Obtain the name or id of the Docker container. Issue the docker cp command and reference the container name or id. The first parameter of the docker copy command is the path to the file inside the container. The second parameter of the docker copy command is the location to save the file on the host.

How do I export a file from a container?

To export a container, we use the docker export command. The documentation describes export as follows: docker export – Export a container's filesystem as a tar archive. As we can see, this is just a regular old Linux file system — the BusyBox file system created when running our image, to be precise.

How do I copy multiple files from Docker container to local machine?

Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH Copy files/folders between a container and the local filesystem Use '-' as the source to read a tar archive from stdin and extract it to a directory destination in a container.


1 Answers

If you want to download files from a docker container to your local machine, you can do it with Docker itself (no need for SSH):

docker cp <containerId>:/path/to/file /host/target/path

Update: I just read that you are connected to a remote container. Then you can use SCP for that:

scp user@host:/path/to/file /local/path
like image 61
Michael Altenburger Avatar answered Oct 01 '22 15:10

Michael Altenburger