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

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