Docker Environment Variables
Environment variables can be set different ways in a Docker Compose yml file. These are set at run time when the container is started up, it is not encoded anywhere inside the image.
Specify a value
Set a variable at run time with a specified value from the Docker-compose.yml file like this:
variableName=value
Use a setting from the local environment
This will set a value from the local environment, for example the local computer environment setting:
variableName
How this would look in a Docker-Compose file:
version: '3'
services:
redis:
image: 'redis:latest'
server:
build:
dockerfile: Dockerfile.dev
context: ./server
volumes:
- /app/node_modules
- ./server:/app
environment:
- REDS_HOST=redis
- REDIS_PORT=6379
In this example we link the REDIS_HOST value directly to the redis
service as defined in the same yml file.