Docker Community Forums

Share and learn in the Docker community.

What is the best way to reference dynamically a namespace?


(Dotrollen) #1

I’m working with a database container and web app container. My goal is to dynamically define the database namespace to the web app. So that every time I spin up a docker-compose stack in it finds the proper host.

For example I am currently manually setting DB_HOSTNAME: test_container_1 in django’s I would like to setup a variable that calls that name no matter what environment or folder it is created in with DB_HOSTNAME: ${database} instead.

I understand how this works in a flat host but how does this work in a docker environment ?

Edit: Disregard :pensive: figured out with the reference file in docker-compose version 3.

I added

links: - db:alias under the host that I want to keep a dynamic name for and that allowed me to reference the host with a environment variable.