Can’t see environment variables set in docker-compose from sbt

I have a dockerfile:


FROM mozilla/sbt:8u212_1.3.4

WORKDIR /app

ADD . /app

RUN sbt compile

CMD sbt run

I have a docker-compose file:

version: '3'
services:
    my-service:
        build: .
        environment:
            - KEY=VALUE

My scala project looks like this:

object Main extends App {
  println(System.getenv("KEY")
}

but when I run docker-compose up it just prints null, instead of VALUE

Source: StackOverflow