简体   繁体   English

如何将文件从一个 docker 容器复制到另一台主机上的另一个容器?

[英]How to copy files from one docker container to another on a different host?

What is the best way to copy files from one docker container to another on a different host?将文件从一个 docker 容器复制到另一台主机上的另一个容器的最佳方法是什么? we ran into couple of issues while trying to do this.我们在尝试这样做时遇到了几个问题。

Issue #1: we provisioned an overlay network and attached containers to it.问题 #1:我们提供了一个覆盖网络并将容器连接到它。 The containers can ping each other using IP address but not using the hostname provided using the -h flag when creating the container容器可以使用 IP 地址相互 ping,但不能使用在创建容器时使用 -h 标志提供的主机名

Container 1:容器 1:

root@rca-ord:/# cat /etc/hosts
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
10.0.29.10  rca-ord

Container 2:容器 2:

root@ica-ord:/# cat /etc/hosts
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
10.0.29.11  ica-ord

ping using hostname fails使用主机名 ping 失败

root@ica-ord:/# ping rca-ord
ping: unknown host rca-ord

ping using IP address works使用 IP 地址进行 ping 工作

root@ica-ord:/# ping 10.0.29.10
PING 10.0.29.10 (10.0.29.10) 56(84) bytes of data.
64 bytes from 10.0.29.10: icmp_seq=1 ttl=64 time=0.684 ms
64 bytes from 10.0.29.10: icmp_seq=2 ttl=64 time=0.434 ms
64 bytes from 10.0.29.10: icmp_seq=3 ttl=64 time=0.731 ms
64 bytes from 10.0.29.10: icmp_seq=4 ttl=64 time=0.672 ms
64 bytes from 10.0.29.10: icmp_seq=5 ttl=64 time=0.545 ms
64 bytes from 10.0.29.10: icmp_seq=6 ttl=64 time=1.25 ms
^C
--- 10.0.29.10 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5010ms
rtt min/avg/max/mdev = 0.434/0.719/1.251/0.258 ms

Looks like we need to run some DNS server.看起来我们需要运行一些 DNS 服务器。 How?如何? what are the details?详情是什么?

Issue #2: we tried to scp using the IP address and it asks for a password - likely the root password as that is the username under which we are logged in. we don't know root password.问题 2:我们尝试使用 IP 地址 scp 并要求输入密码 - 可能是 root 密码,因为这是我们登录的用户名。我们不知道 root 密码。

root@ica-ord:/# scp 10.0.29.10:test-file.txt .
The authenticity of host '10.0.29.10 (10.0.29.10)' can't be established.
ECDSA key fingerprint is SHA256:Bdnjhvxlk1ILzWpa8tvu+YLaHRqh9XBftIoeLSpKLBQ.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.29.10' (ECDSA) to the list of known hosts.
root@10.0.29.10's password: 

we are thinking there ought to be a simple way to copy files between containers on multiple hosts.我们认为应该有一种简单的方法来在多个主机上的容器之间复制文件。 is there any?有没有?

Docker doesn't provide anything magical to make this easy. Docker 没有提供任何神奇的东西来使这变得容易。 Typically Docker-packaged components don't communicate with each other by sharing files;通常,Docker 打包的组件不会通过共享文件相互通信; instead they talk to each other using network protocols like HTTP, or by using a message-bus system like RabbitMQ.相反,它们使用网络协议(如 HTTP)或使用消息总线系统(如 RabbitMQ)相互通信。

This problem isn't fundamentally different from taking two non-Docker server processes that used to run on the same host and splitting them on to different hosts, except that Docker's filesystem isolation means that just getting the file on to the other host doesn't necessarily make it visible to the other container.这个问题与将过去运行在同一主机上的两个非 Docker 服务器进程并将它们拆分到不同的主机上没有本质区别,只是 Docker 的文件系统隔离意味着只是将文件放到另一台主机上不会必须使它对另一个容器可见。

A typical architecture I've seen around this looks like this:我在这方面看到的典型架构如下所示:

  1. You have some sort of shared networked file-oriented storage layer (an NFS server, Amazon S3, ...).您有某种面向文件的共享网络存储层(NFS 服务器、Amazon S3 等)。 Both services have the required setup to communicate with it.这两个服务都具有与之通信所需的设置。

  2. The producing service writes the file to the storage layer.生产服务将文件写入存储层。

  3. The producing service contacts the consuming service (by an HTTP connection; to a shared RabbitMQ queue; either knowing the other service's server's hostname or using a service-discovery system like Consul or Kubernetes Service objects to find it) and tells it where the file is.生产服务联系消费服务(通过 HTTP 连接;到共享的 RabbitMQ 队列;要么知道其他服务的服务器的主机名,要么使用诸如 Consul 或 Kubernetes Service 对象之类的服务发现系统来查找它)并告诉它文件在哪里.

  4. The consuming service reads the file and processes it.消费服务读取文件并处理它。

This setup has the advantages that you don't need to deal with N services trying to set up authenticated scp to N other services (or even M other hosts), you don't have to deal with the complexities of Docker volume sharing (and concurrent access and permission management), and it still works even if a service moves to a different host and doesn't immediately have a local copy of the file.这种设置的优点是您不需要处理尝试将经过身份验证的 scp 设置为 N 个其他服务(甚至 M 个其他主机)的 N 个服务,您不必处理 Docker 卷共享的复杂性(和并发访问和权限管理),即使服务移动到不同的主机并且没有立即拥有文件的本地副本,它仍然可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将构建文件从一个容器复制到另一个容器或 docker 上的主机 - How to copy build files from one container to another or host on docker 如何将文件从主机复制到 Docker 容器? - How to copy files from host to Docker container? Docker 如何将文件从容器复制到主机? - Docker how to copy files from container to host? 如何将文件从一台服务器上运行的一个容器(Docker)复制到另一台服务器上运行的另一个容器? - How to copy a file from one container (Docker) running in one server to another container running on a different server? 如何将文件从Docker Ubuntu容器复制到Windows主机 - How to Copy Files From Docker Ubuntu Container to Windows Host 如何使用docker cp将多个文件从容器复制到主机 - How to copy multiple files from container to host using docker cp 如何将文件从Windows主机复制到Docker容器 - How to copy files from Windows host to Docker container 如何将文件从当前Docker容器复制到另一个容器 - How copy files from current docker container to another container Docker:如何将带有数据的容器从一台主机传输到另一台主机 - Docker: How to transfer container with data from one host to another 从一个 Docker 容器内部,如何连接到同一 Docker 主机上另一个 Docker 容器的端口? - From inside one Docker container, how to connect to the port of another Docker container on the same Docker host?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM