I am trying to mount a nginx server with docker compose in an instance of EC2 I need to pass an environment variable, that varibale is defined in the user data of the instance
I tryed to uploaded it with the environment option of the docker compose but when the nginx is uploaded it creates a static code and can't be replaced making reference with "process.env.KEY", I want to know if there's a way to pass the variable to nginx maybe before the build, or update the static files after they have been created
userdata.sh
#!/bin/bash
echo KEY=keyexpected >> /etc/environment
docker-compose.yml
version: "3.1"
services:
container1:
container_name: container1
image: image1
restart: always
network_mode: bridge
environment:
- KEY=${KEY}
ports:
- 8080:80
container2:
container_name: container2
image: image2
restart: always
network_mode: bridge
ports:
- 3000:3000
Javascript file that will be build by ngnix
const path = { key: process.env.KEY };
console.log(path.key)
Dockerfile of Node project
FROM nginx:1.15.2-alpine
RUN rm -rf /usr/share/nginx/html/
COPY nginx/default.conf /etc/nginx/conf.d/
COPY build /usr/share/nginx/html/
EXPOSE 80
ENTRYPOINT nginx -g 'daemon off;'
expected: console.log(path.key) ----> "keyexpected"
actual: process.env.KEY is undefined