docker-compose: using multiple Dockerfiles for multiple services

前端 未结 4 1556
陌清茗
陌清茗 2021-02-19 01:37

I\'m using docker-compose and I\'d like to use different Dockerfiles for different services\' build steps. The docs seem to suggest to place different Dockerfiles in different d

4条回答
  •  后悔当初
    2021-02-19 02:21

    This is not possible due to the way Docker handles build contexts.

    You will have to use and place a Dockerfile in each directory that becomes part of the Docker build context for that service.

    See: Dockerfile

    You will in fact require a docker-compose.yml that looks like:

    service1:
        build: service1
    
    service2:
        build: service2
    

    See: docker-compose

    Update:

    To address your particular use-case -- Whilst I understand what you're trying to do and why I personally wouldn't do this myself. The isolation is a good thing and helps to manage expectations and complexity. I would perform the "database creation" as either another container based off your app's source code or within the app container itself.

    Alternatively you could look at more scripted and template driven solutions such as shutit (I have no experience in but heard god thigns about).

    FWIW: Separation of concerns ftw :)

提交回复
热议问题