2

I'm new to Docker and I want to copy files to/from my local machine directly to a docker container that's on a remote machine without having to scp files from my local to my remote and then using docker cp to copy those files to the container. My container does not have an SSH server installed on it nor do I want to rebuild my image to include it.

I tried following solution given by the second answer here:How to SSH into Docker? . I ran the following command on my remote machine that hosts Docker: docker run -d -p 2222:22 -v /var/run/docker.sock:/var/run/docker.sock -e CONTAINER=kind_tu -e AUTH_MECHANISM=noAuth jeroenpeeters/docker-ssh

Where kind_tu is the name of my running container.

On my local machine I then used: ssh -L 2222:localhost:2222 remote_account_name@remote_ip and then scp -P 2222 test_file remote_account_name@remote_ip:/destination/path (I'm also not familiar with port forwarding so I'm not sure if my notation is correct). When doing this, I get the following:

ssh: connect to host remote_ip port 2222: Connection refused

lost connection

Could this be an issue with the firewall since the remote machine is on my school's campus?

In all, I'm not sure if what I'm doing is even remotely correct.

invad0r
  • 908
  • 1
  • 7
  • 20
sarah
  • 21
  • 1
  • 3
  • Since Docker containers get deleted and recreated fairly routinely, trying to copy files directly into the container filesystem (where they'll get lost as soon as the container is deleted) usually isn't the right approach. You might consider bind-mounting a host directory (saving a step of copy), or even building these files directly into your image. – David Maze Apr 23 '20 at 11:15
  • Hi David, I'm currently running simulations from software built in my container, and I need to repeatedly move out visualization files from the remote container to my host computer in order to run them into a visualization program. I was wondering if you could elaborate more on what bind-mounting is and if it would be the best solution to my problem – sarah Apr 23 '20 at 18:06

1 Answers1

-1

According to your comment as a reply to David's, here is the explanation how to bind-mount the directory for your visualization files to your container:

On the host system create a directory, e.g. mkdir /home/sarah/viz/. Then, mount it to your docker container, using e.g.

docker run -v /home/sarah/viz:/data/viz … kind_tu …

Your viz software inside the kind_tu container should place the files in the directory /data/viz – which then lands in /home/sarah/viz/ on the host system, where you can download them to your local computer with scp or rsync or however you can connect to the remote machine.

You can also use docker-compose to have a more persistent environment. Write a file docker-compose.yml with the bind-mount and all the other configuration of the kind_tu container:

version: '3'
  services:
    kind_tu:
      image: your_viz_software_image:latest
      volumes:
        - /home/sarah/viz:/data/viz:rw
      …

Then, instead of docker run … you can just do docker-compose up -d and everything acts according to the config in the compose-file.

mcnesium
  • 1,423
  • 2
  • 16
  • 21