0

I have a docker-compose.yaml file and a .env file. If I declare a variable in the env file, I can access it in docker-compose. So, this is good.

But, I would like to change nginx's default.conf properties, namely the server_name = xxx to be generated from the value I provide in the env.

So, my env looks like this (only sharing a portion)

#.env
NGINX_SERVER_NAME=dev.example

In docker-compose I mention this variable here:

nginx:
  container_name: ${APP_NAME}-server
  environment:
    - SERVER_NAME=${NGINX_SERVER_NAME}

And in default.conf I simple call the variable like this:

server_name ${SERVER_NAME};

I am expecting the default.conf to contain server_name dev.example but it contains the token i.e. ${SERVER_NAME}

How can I achieve what I am looking for? Thanks

elektra
  • 55
  • 2
  • 19

1 Answers1

1

this seems ok to me. try to use quote around your env variable in compose file.

nginx:
  container_name: ${APP_NAME}-server
  environment:
    - SERVER_NAME="${NGINX_SERVER_NAME}"

or try to write your env variable like this.

nginx:
  container_name: ${APP_NAME}-server
  environment:
    SERVER_NAME: "${NGINX_SERVER_NAME}"
m303945
  • 883
  • 5
  • 9