How to pass environment variables to docker-compose's applications

You can use environment like this:

    service-a:
        build:
          context: .
          dockerfile: DockerfileA
        command: node serviceA.js
        environment:
            KEY=DockerComposeRun

Refer at: https://docs.docker.com/compose/environment-variables/


To safely pass sensitive configuration data to your containers you can use Docker secrets. Everything passed through Secrets is encrypted.

You can create and manage secrets using the commands below:

docker secret create
docker secret inspect
docker secret ls
docker secret rm

And use them in your docker-compose file, either referring to existing secrets (external) or use a file:

secrets:
  my_first_secret:
    file: ./secret_data
  my_second_secret:
    external: true