Copy file from remote docker container

10,301

Solution 1

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

Solution 2

sounds like a great application for docker context.

  • create a context: docker context create myserver --docker "host=ssh://myserver.com"
  • copy files as usual: docker --context myserver cp /local/path/file.txt containername:/path/in/container/

This works in reverse, too, to get files from the remote docker container to your local file system. Best to have key-based access defined for your remote server.

Another solution is to create a volume, start a docker container temporarily that exports this volume to the world (ftp, smb, nfs, you name it). Once that is done, you can then mount that volume to your target container and have access to the files. This one, too, obviously works just fine in reverse.

Share:
10,301
Andrej Hucko
Author by

Andrej Hucko

I'm young computer scientist experienced with databases like PostgreSQL or MySQL and visualization libraries like D3.js or Vis.js. Web technology preffered: Ruby on rails Interests: Data science and Visualizations. Feel free to contact me!

Updated on June 24, 2022

Comments

  • Andrej Hucko
    Andrej Hucko almost 2 years

    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. 🙂

  • Barpa
    Barpa about 3 years
    I think this is not the correct answer to the question. The first command just copy a file from a container to a remote machine and the second command copy a file from a remote machine to local. The question is about how to copy a file from a remote container to a local machine.