Search code examples
dockerwebvirtual-machinescp

Downloading/uploading a file/folder directly from/to a docker container running on a web host to/from a local machine using SCP


So far, I have always copied files from the docker container to my VM first (web host), and later, run scp command line from my local machine to download it from the VM. Similar scenario happening for uploading files/folders. Is there a direct way to do that using scp?


Solution

  • In order to directly copy from your container you need sshd installed on the container and expose an port for ssh to public when you run the container. Take in count that if you do you have to make sure that ssh is properly configured and secured.

    Example: *We take in count that you already have ssh configured on the container

    docker run -d -p 8000:22 --name docker image
    scp -P 8000 username@myserver.com:/root/file.txt ~/file.txt