Docker link 到之前启动的容器

Docker link to previously started containers

我想对一些先前启动的容器进行 docker-compose run 一次性 运行 。我的 docker-compose.yml 文件将如下所示:

one_shot_service:
 ...
  links:
    - long_running_service:docker
long_running_service:
  ...

我的工作流程是:

  1. 启动长运行ning服务 docker-compose up long_running_service
  2. 运行一次发球多次。 docker-compose run --no-deps one_shot_service

当我这样做时,one_shot_service 上的 /etc/hosts 文件不包含 docker 的条目。当我 运行 没有 --no-deps 时就可以了。我不想 运行 没有 no-deps 的原因是 long_running_service 需要很长时间才能启动。

长话短说,我如何 link 到现有容器?

可以使用external_links directive

示例:

external_links:
    - long_running_service:your_alias