How can I access MONGODB url from another container..
My containers are..
- Database (Mongo image)
- Api (Private container with node api)
- UI (Private container with nginx)
In API app I need to use API_MONGO_URL
environment variables to reference MongoDB url.
How can I update this variable after mongodb
container created?
version: "3"
volumes:
mongo_data:
driver: local
services:
mongodb:
image: mongo:latest
container_name: db
command: --smallfiles --rest
volumes:
- mongo_data:/data/db
ports:
- "27017:27017"
environment:
- MONGODB_PORT_27017_TCP_ADDR=$MONGODB_PORT_27017_TCP_ADDR
- MONGODB_PORT_27017_TCP_PORT=${MONGODB_PORT_27017_TCP_PORT}
api:
image: api:latest
container_name: api
depends_on:
- mongodb
environment:
- API_MONGO_URL= "mongodb://${MONGODB_PORT_27017_TCP_ADDR}:${MONGODB_PORT_27017_TCP_PORT}/api"
links:
- mongodb
expose:
- "3000"
web:
image: ui:latest
container_name: ui
ports:
- "80:80"
links:
- api