How to call value declared in docker-compose file in entrypoint.sh file

I have a docker-compose file as below:

version: '2'

services: 
        influxdb:
                   image: influxdb:1.7.6-alpine
                   args: 
                           - INFLUXDB_DB=influx

And I have entrypoint.sh file as below:

#!/bin/bash
node script.js --database ${INFLUX_DB}

But while building image value is not being called. How to solve this?

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.

Hi @rajchaudhuri,
Look above edited docker-compose yml file with args.
And I had a Dockerfile like below:

ARG INFLUX_DB
ENTRYPOINT ["./entrypoint.sh"] 

And entrypoint.sh file as below:

#!/bin/bash
node script.js --database ${INFLUX_DB}

When I run container with docker-compose up, the value in entrypoint.sh file is empty for ${INFLUX_DB}.

How to make value called inside entrypoint.sh OR How should ENTRYPOINT execute this with value from docker-compose file?

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.

Wait, I thought you wanted the variable during build time. If it is at run time, then your compose file should look like this:

services: 
  influxdb:
    image: influxdb:1.7.6-alpine
    environment: 
      - INFLUXDB_DB=influx

Basically, use environment, not args.

Sorry, I misunderstood the question. My bad.