How do you pass an environment variable to a Docker Compose service container?
Experience Level: Junior
Tags: Docker Compose
Answer
Under a service, add environment section that contains with list of environment variables like this:
version: "3.4"
services:
my-service:
image: busybox
environment:
- VARIABLE1=value1
- VARIABLE2=value2
Related Docker Compose job interview questions
How do you create a Docker Compose file that is parametrized using environment variables?
Docker Compose JuniorHow do you create a custom network and configure a Docker Compose service to use this network?
Docker Compose JuniorHow do you display images of all running containers that were created based on running Docker Compose?
Docker Compose JuniorHow do you list all running containers that were created based on running Docker Compose?
Docker Compose JuniorHow do you stop Docker Compose services that were previously executed in a detached mode and also delete all their containers?
Docker Compose Junior