How to specify multiple "env_files" for a docker compose service?

Currently I have setup my service like the following.

version: '3'
services:
  gateway:
    container_name: gateway
    image: node:lts-alpine
    working_dir: /
    volumes:
      - ./package.json:/package.json
      - ./tsconfig.json:/tsconfig.json
      - ./services/gateway:/services/gateway
      - ./packages:/packages
      - ./node_modules:/node_modules
    env_file: .env
    command: yarn run ts-node-dev services/gateway --colors
    ports:
      - 3000:3000

So I have specified one env_file. But now I want to pass multiple .env files.

Unfortunately, the following is not possible:

    env_files:
       - .env.secrets
       - .env.development

Is there any way to pass multiple .env files to one service in docker-compsoe?


You can specify multiple env files on the env_file option (without s).

For instance:

version: '3'

services:
  hello:
    image: alpine
    entrypoint: ["sh"]
    command: ["-c", "env"]
    env_file:
      - a.env
      - b.env