How do tell Docker Compose to use custom .env2 file without passing it in command-line argument?

Experience Level: Senior
Tags: Docker Compose

Answer

Add env_file: property to your service definition like this:

version: "3.9"
services:
  my-service:
    env_file:
    - ./.env2
    image: busybox

Comments

No Comments Yet.
Be the first to tell us what you think.
Docker Compose
Docker Compose

Are you learning Docker Compose ? Try our test we designed to help you progress faster.

Test yourself