0

我假设有一种方法可以通过以下一个或组合进行链接:链接、external_links 和网络。

有任何想法吗?到目前为止,我空手而归。

这是一个 Docker-compose 的示例片段,它从一个单独的 Ubuntu docker 中启动

version: '2'
 services:
  web:
   build: .
   depends_on:
    - redis
 redis:
  image: redis

我希望能够从启动 docker-compose 的 Docker 连接到 redis 端口。

我不想绑定主机上的端口,因为这意味着我将无法从同一模型启动多个 docker-compose。

-- 上下文 -- 我正在尝试从 Jenkins maven 构建 Docker 中运行 docker-compose,以便我可以运行测试。但我一辈子都无法让原始 Docker 访问 docker-compose 上的暴露端口

4

1 回答 1

0

Reference the machines by hostname, v2 automatically connects the nodes by hostname on a private network by default. You'll be able to ping "web" and "redis" from within each container. If you want to access the machines from your host, include a "ports" definition for each service in your yml.

The v1 links were removed from the v2 compose syntax since they are now implicit. From the docker compose file documentation

links with environment variables: As documented in the environment variables reference, environment variables created by links have been deprecated for some time. In the new Docker network system, they have been removed. You should either connect directly to the appropriate hostname or set the relevant environment variable yourself...

于 2016-06-11T11:13:10.893 回答