Docker Community Forums

Share and learn in the Docker community.

Docker compose requiring files that aren't related to the service?

I have reproduced my issue in a a simple docker file:

version: "3.3"
services:
  node:
    entrypoint: "/bin/bash -c"
    image: node:14.17.4
    working_dir: /app/
    env_file:
      - .env

  node2:
    entrypoint: "/bin/bash -c"
    image: node
    working_dir: /app/
    env_file:
      - .env
      - .env.another

Now, with both .env and .env.another in the same directory, both of these commands execute fine:

➜ docker-compose run node  "node -v"
Creating docker-huh_node_run ... done
v14.17.4
➜ docker-compose run node2  "node -v"
Creating docker-huh_node2_run ... done
v16.10.0

However, if I now remove .env.another from disk which is not required by node, I get the following:

➜  docker-compose run node  "node -v" 
ERROR: Couldn't find env file: /Users/USER/path/to/here/.env.another

My expectation would be that without this file, this service inside the docker would execute fine? What am I missing here?