Compose: [Proposal] yml config merging should take empty arrays as a volontary attempt to reset the key

Created on 8 Dec 2015  Â·  4Comments  Â·  Source: docker/compose

Not sure if the title is very clear, so I'll expand my idea here.

Given a docker-compose.yml file:

nginx:
    image: nginx
    volumes:
        - './test:/test'

and a extra.yml file:

nginx:
    volumes: []

Then the resulting volumes for docker-compose -f docker-compose.yml -f extra.yml up should be an empty array.

Note this applies when using extends too.
This behavior should apply for every merged array (environment/labels/…)

The idea is that if I specify an empty array, it's for a reason, otherwise I simply would not specify the key at all.

The consequence is that I can describe a working dev setup (mounting the sources from the host f.e), and use an extra file for a staging environment f.e, which has no host volumes.

Hope I'm clear :) Otherwise, just tell me, I'll try to explain my use case in a better way.

Most helpful comment

Some feedback here.

The argument

to keep the logic simple

feels light, as this would only concern people who deliberately need for this and would not make it more complicated for the rest of the world.

Also, the suggested solution doesn't work in the general case.

In my case, I use docker-compose.yml to set my development environment, so that a dev only has to run docker-compose start (or up or run) without a chance of making a mistake. And there, a development database is set:

web:
  build: .
  command: npm start
  ports:
    - "3000:3000"
  volumes:
    - .:/myapp
  links:
    - mongodb
  environment:
    PORT: 3000
mongodb:
  image: mongo
  command: "--smallfiles --logpath=/dev/null"

On the other hand, I use docker-compose -f docker-compose-production.yml start in production, with extra config, and no DB since it is elsewhere.

web:
  extends:
    file: docker-compose.yml
    service: web
  ports:
    - "80:3000"
    - "443:4443"
  links: []
  environment:
    NODE_ENV: production
    MONGODB_URI: mongodb://login:[email protected]:27017

Hence I'd need to override the links key with an empty array.

I guess discussing this practice here would be off-topic, but I wouldn't mind.

I you say something like: "It is a pain, I don't want to write that feature" then fine (eventually I could work on it), but "it will make it too complicated" is not receivable to me. 😄

Thanks for reading

All 4 comments

I understand your use case, but we deliberately don't do this in order to keep the logic simple. The recommended way to achieve what you want is to leave the volume mounts out of your core docker-compose.yml and put them in docker-compose.override.yml.

# docker-compose.yml
nginx:
  image: nginx

# docker-compose.override.yml
nginx:
  volumes:
    - ./test:/test

Compose looks for docker-compose.override.yml by default, so you don't need to pass any arguments to docker-compose up in development.

To run without it, use docker-compose -f docker-compose.yml up.

Thanks! Didn't think of that. looks like it perfectly fits my needs. Closing.

Some feedback here.

The argument

to keep the logic simple

feels light, as this would only concern people who deliberately need for this and would not make it more complicated for the rest of the world.

Also, the suggested solution doesn't work in the general case.

In my case, I use docker-compose.yml to set my development environment, so that a dev only has to run docker-compose start (or up or run) without a chance of making a mistake. And there, a development database is set:

web:
  build: .
  command: npm start
  ports:
    - "3000:3000"
  volumes:
    - .:/myapp
  links:
    - mongodb
  environment:
    PORT: 3000
mongodb:
  image: mongo
  command: "--smallfiles --logpath=/dev/null"

On the other hand, I use docker-compose -f docker-compose-production.yml start in production, with extra config, and no DB since it is elsewhere.

web:
  extends:
    file: docker-compose.yml
    service: web
  ports:
    - "80:3000"
    - "443:4443"
  links: []
  environment:
    NODE_ENV: production
    MONGODB_URI: mongodb://login:[email protected]:27017

Hence I'd need to override the links key with an empty array.

I guess discussing this practice here would be off-topic, but I wouldn't mind.

I you say something like: "It is a pain, I don't want to write that feature" then fine (eventually I could work on it), but "it will make it too complicated" is not receivable to me. 😄

Thanks for reading

agree with @augnustin, would be a lot easier to leave the development settings in the default docker-compose.yml for simplicity of use in everyday life, and allow overwriting those settings (including "erasing" keys) in the specific production file (or whatever other environment you might have).

Was this page helpful?
0 / 5 - 0 ratings