Docker链接到以前启动的容器

我想执行一个docker-compose run ,将运行一些以前启动的容器。 我的docker-compose.yml文件如下所示:

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

我的工作stream程是:

  1. 启动长时间运行的服务docker-compose up long_running_service
  2. 多次运行一次性服务。 docker-compose run --no-deps one_shot_service

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

长话短说,我如何链接到现有的容器?

您可以使用external_links指令 。

例:

 external_links: - long_running_service:your_alias