首页 > 解决方案 > 两个容器之间的共享命名卷在其中一个容器中为空

问题描述

我想在两个容器之间共享一个命名卷,如下所示:

version: '3.5'

services:
  service1:
    # ...
    volumes:
      - certificates:/path/to/certificates
  service2:
    # ...
    volumes:
      - certificates:/path/to/customcertificates

volumes:
   certificates:

一开始,数据只存在于 service1-container 中/path/to/certificates。使用上面的卷配置,service2中的数据 /path/to/customcertificates是空的。

如何将这些数据从 service1 共享到 service2?

标签: dockerdocker-compose

解决方案


我在写这个问题时找到了解决方案。这不是最佳的,但对我来说还可以。我仍然会发布带有答案的问题,因为我花了一段时间才弄清楚并且可能会帮助某人:

我需要像这样更改卷定义:

volumes:
   certificates: {}

推荐阅读