Setting your environment variables (ENV)

For convenience, we provide several ways to set your environment variables.

Dotenv

The dotenv methods is used when you provide a .env file in your project root folder. The format of .env is simple and efficient, here is an exemple:

VARIABLE1=value1
VARIABLE2=value2
VARIABLE3=value3
For more information you can have a look at the dotenv NPM.

Once you have a .env file, make sure to add the following lines in your docker-compose.yml (example):

version: '3'
services:
  www:
    env_file:
      - .env
    volumes:
      - /opt/app:/opt/app/
    ports:
      - '80:80'
    build:
      context: .

The env_file instruction is what tells our system to load the environment variables located in .env.

Dockerfile

Docker provides an ENV commands allowing to set environment variables. To use this method, just add ENV commands in your Dockerfile. More information on ENV in Dockerfile.