I've found that if I override an image's ENTRYPOINT in a docker-compose service entry, that it ignore variables defined in the environment section but will read them from an env file, e.g.
someserver:
image: "some-server:latest"
restart: always
ports:
- "8849:8849"
environment:
javaMemoryLimit: 3056M
JAVA_OPTS: "-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=8849 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.rmi.port=8849 -Djava.rmi.server.hostname=localhost"
entrypoint: java ${JAVA_OPTS} -Xmx${javaMemoryLimit} -jar /app.jar
When I do a docker-compose up
with this I get warnings about variable not being set:
WARNING: The JAVA_OPTS variable is not set. Defaulting to a blank string.
WARNING: The javaMemoryLimit variable is not set. Defaulting to a blank string.
But when I define the variable in an env file, e.g. .env
javaMemoryLimit=2098M
JAVA_OPTS=-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=8849 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.rmi.port=8849 -Djava.rmi.server.hostname=localhost
Then variables are expanded as expected.