【发布时间】:2019-09-04 09:01:24
【问题描述】:
在 circleci 上,当我为一项工作声明多个 docker 时:
dockers:
app: company/image
selenium: selenium/image
app 将公开端口 4000,而 selenium 将公开端口 4444。 然后从 app 容器中,我可以通过 localhost:4444 访问 selenium 服务,在 selenium 容器上,我可以通过 localhost:4000 访问 app webserver。
docker-compose,然而,行为不同。我只允许我从 app 访问 selenium:4444,从 selenium 访问 app:4000。
我希望 docker-compose 的行为类似于 circleci,它允许我使用 localhost:port 访问其他服务。我该怎么做?
【问题讨论】:
-
docs.docker.com/compose ?您可以使用
expose将端口暴露给其他服务,而不是主机;使用ports向主机公开端口。 It's all in the docs 并且有很多指南。 -
是的,docker-compose 端口设置允许通过“container:port”而不是“localhost:port”从一个容器访问另一个容器。