Jordi
Jordi

Reputation: 23257

Docker mongos: provide config server on environment variables

I've deployed a sharded mongodb cluster for development with one shard and one config server.

Into my application stack I need to deploy a mongos in order to connect to config server. Related snippet code docker-compose.yml:

mongodb:
    image: mongo:3.6
    command: mongos --configdb cfgrs/cfg1:27017 --bind_ip_all
    ports:
    - 27078:27017
    networks:
      - services-net
    deploy:
      replicas: 0

As you can see at --configdb cfgrs/cfg1:27017, config server location is provided in a hard-written way.

I'd like to provide this information using an environment variable.

How could I get it?

Upvotes: 1

Views: 106

Answers (1)

bellackn
bellackn

Reputation: 2184

You could use an .env file for this (cf. the Docker docs).

.env

CONFIG_SERVER_LOCATION=cfgrs/cfg1:27017

docker-compose.yml

mongodb:
    image: mongo:3.6
    command: mongos --configdb $CONFIG_SERVER_LOCATION --bind_ip_all
    ports:
    - 27078:27017
    networks:
      - services-net
    deploy:
      replicas: 0

Upvotes: 1

Related Questions