LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   docker-conpose use .env to change service names (https://www.linuxquestions.org/questions/linux-software-2/docker-conpose-use-env-to-change-service-names-4175653186/)

funkytwig 05-02-2019 10:03 AM

docker-conpose use .env to change service names
 
I am using nginx-proxy so I can host multiple WordPress docker containers on a server. Because of this, the service name for the DB (MariaDB) has to be different for each of the WordPress docker-compose.yml files (there is one for each site). I am using .env to set variables so I can use the same docker-compose.yml (so I can easily change them all, i.e. use symbolic links).

Problem is you cant use a variable for the service name. i.e. the following is not allowed:

version: '3'

services:

${DB_SERVICE}:
image: mariadb
volumes:
...

I did try COMPOSE_PROJECT_NAME which I thought appended to the service name but it does not (it only appends to the name of the created containers).

Any idea how I can do this?
Ben

pan64 06-02-2019 08:22 AM

if this https://docs.docker.com/compose/environment-variables/ did not work for you: it looks like the only way is to generate them using a common template


All times are GMT -5. The time now is 01:29 AM.