简体   繁体   中英

Docker-compose run container with all others

Given a docker-compose-core.yml :

version: "3"

services:

  gradle:
    image: gradle:5.4.1-jdk8
    command: gradle build release

  kafka:
    image: kafka

And other(s) docker-compose-{es6/es7}.yml :

version: "3"

services:

  elasticsearch:
    image: elasticsearch{6/7}

I want to run:

COMPOSE_FILE=docker-compose.yml:docker-compose-es6.yml 
docker-compose run --rm gradle

And starts ALL containers defined. I cant use depends_on because this must be dynamic.

You can run docker-compose -f docker-compose-core.yml -f docker-compose-es6.yml run gradle , to run both files together with keys in the latter overriding keys in the former. So you can add on a key to gradle in docker-compose-es6.yml like so:

version: "3"

services:

  gradle:
    depends_on:
      - elasticsearch

  elasticsearch:
    image: elasticsearch{6/7}

The docs regarding merging multiple compose files

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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