docker-compose ignores `configs:` section

Viewed 3360

I've got a docker-compose service definition with a configs section as follows:

# api.yml file
version: '3.3'

services:
  api:
    ...
    configs:
      - source: api_config
        target: /env.cfg

configs:
  api_config:
  file: ./config/my.cfg

When I use this file to drive a swarm, i.e. I deploy it with docker stack deploy ... the config file is properly provided into the running containers.

However, when I try to run a local version of the api via docker-compose -f api.yml up I get a startup failure complaining of my api service that it can't find its config. (NB: docker-compose itself doesn't report any errors.)

Are configs sections not supported with plain docker-compose usage?

The docs don't explicitly say so although some wording seems to indicate this is for stacks only:

Note: The config must already exist or be defined in the top-level configs configuration of this stack file, or stack deployment will fail.

2 Answers

Yes, configs is not supported in docker compose according to this github issue. I've just wasted my time trying it after reading the docs. You need to write a custom Dockerfile to build the config file.

Related