【问题标题】:Connect to from one container to another container from diffrent docker-compose [duplicate]从不同的docker-compose从一个容器连接到另一个容器[重复]
【发布时间】:2021-09-29 11:01:25
【问题描述】:

我的第一个 docker-compose 看起来像

version: '3.4'

services:
  php-fpm:
    build:
      context: ./docker
      dockerfile: Dockerfile
      target: php-fpm
    ports:
      - 80:80
      - 443:443
    env_file:
      - .env

我的第二个 docker-compose 看起来像这样:

version: '3.4'

services:
  web:
    build:
      context: ./docker
      dockerfile: Dockerfile
      target: web
    ports:
      - 8080:80

现在我想将 curlphp-fpm 容器转移到 web 容器。所以我正在执行这个命令:

docker-compose exec php-fpm curl http://web:80/

我收到错误:

curl: (6) Could not resolve host: web

当我在主机上的浏览器中输入地址http://localhost:8080 时,我可以看到来自web 容器的响应。

总结一下:我的问题是:如何从php-fpm 容器卷曲到web 容器?

附言。在实际项目中,这些 docker-compose 文件看起来要复杂得多,我无法将它们合并到一个 docker-compose 文件中。

【问题讨论】:

    标签: docker networking docker-compose


    【解决方案1】:

    【讨论】:

    • 您能否添加一个建议解决方案的简短示例,因此这不是仅链接的答案?
    猜你喜欢
    • 2019-02-24
    • 2017-10-15
    • 2021-04-24
    • 2016-06-15
    • 1970-01-01
    • 2020-01-30
    • 1970-01-01
    • 2021-03-04
    • 2021-12-08
    相关资源
    最近更新 更多