简体   繁体   English

如何在我的docker-compose.yml文件中指定服务,该服务在docker hub中具有自己的docker-compose.yml文件?

[英]How to specify a service in my docker-compose.yml file that has its own docker-compose.yml file in docker hub?

So I am trying to set up a few services in my local docker environment. 因此,我试图在本地docker环境中设置一些服务。 One of the services, as defined in my docker-compose.yml file, is as follows: 在我docker-compose.yml文件中定义的服务之一如下:

version: "3"

services:
  solr:
    image: solr:latest
    ports:
      - "8983:8983"
    container_name: solr

...which is pretty straightforward. ...非常简单。

However, I also want to set up another service that has its own docker-compose.yml in it. 但是,我也想设置另一个具有自己docker-compose.yml的服务。 If I simply specify a FROM in the Dockerfile for this service, it doesn't work as expected as the repo's docker-compose.yml includes services from other repositories as well. 如果我只是在Dockerfile中为此服务指定了FROM ,那么它就不能按预期工作,因为存储库docker-compose.yml包含来自其他存储库的服务。

What is the right way to configure such a service that has its own docker-compose.yml file? 配置具有自己docker-compose.yml文件的服务的正确方法是什么?

Use extend in yml file to call another docker-compose file. 使用yml文件中的extend调用另一个docker-compose文件。 When defining any service in docker-compose.yml, you can declare that you are extending another service like this: 在docker-compose.yml中定义任何服务时,您可以声明要扩展另一个服务,如下所示:

 web:
   extends:
     file: common-services.yml
     service: webapp

Ref : https://docs.docker.com/compose/extends/#understand-the-extends-configuration 参考: https : //docs.docker.com/compose/extends/#understand-the-extends-configuration

Note : extend option is removed from docker-compose version-3 and it is available only in version-2 注意: 扩展选项已从docker-compose版本3中删除,并且仅在版本2中可用

Ref : https://docs.docker.com/compose/extends/#extending-services 参考: https : //docs.docker.com/compose/extends/#extending-services

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM