scp to Docker Container that is on Remote Host

Viewed 6524

I am running two AWS EC2 Ubuntu instances in separate regions (Ireland and London). A Docker container is running on each instance.

An established IPSec connection exists:

root@ip-10-0-1-178:/mnt# ipsec status
Security Associations (1 up, 0 connecting):
Ireland-to-London[2]: ESTABLISHED 37 seconds ago, 
172.17.0.1[34.X.X.X]...35.X.X.X[35.X.X.X]

Here are some IP's for each:

Ireland  
Public IP: 34.X.X.X
Private IP: 10.0.1.178
VPC CIDR Block: 10.0.0.0/16
London  
Public IP: 35.X.X.X
Private IP: 10.10.1.187
VPC CIDR Block: 10.10.0.0/16
Docker(same for both)
Public IP: 172.17.0.1
VPC CIDR Block: 172.17.0.0/16
Ports open: 500 and 4500

I cannot figure out how to transfer files using scp from a Docker container on one instance to the Docker container on the other.

2 Answers

Make sure your docker image has port 22 mapped to 500/4500 so you should be able to use

scp -P YOUR_PORT file USERNAME@AWS_IP:/file  

You can also use docker cp to copy the file to the host machine, then scp to the other machine and then use docker cp to copy to docker image as a workaround.

List of things you need to do.

  1. Enable ssh ports(e.g 22) on both containers.
  2. EXPOSE / forward the container ports to the host machine ports(e.g. 2200:22) on both machines.
  3. Open the forwarded ports on the host machines in firewall.
  4. Now scp -P 2200 localfile.txt <london_user>@<london_public_ip>:<remote path>.
  5. I ignored the part were you configure password, or key based communication, there are already many resources on that.
Related