Because variables that you put under a service in a docker-compose file are available when a container is created, not at the time of building images. Use args instead. Look here (https://docs.docker.com/compose/compose-file/#args) for details.
Runtime variables are passed as environment, not as arg.
ARGs form the Dockerfile are only present during build time. If you want the value of an ARG to be present as the default value for a container, you have to assign the ARG to an ENV as well.
ARG INFLUX_DB
ENV INFLUX_DB=$INFLUX_DB
This allows to inject the value for INFLUX_DB from outside during build time and set it as a default in the image.