I'm using docker with AWS ECS and I want to pass env variables using docker to my nodejs application.
My app.js is simple, it have route that tell me the value of SOME
variable:
app.get('/test', (req, res) => res.status(200).send(`${process.env.SOME} OK`));
This is how I update the AWS ECS service:
docker-compose -f .docker/docker-compose.myweb.ecr.yml build www-app
docker-compose -f .docker/docker-compose.myweb.ecr.yml push www-app
aws ecs update-service --cluster web --service www --force-new-deployment
Dockerfile:
FROM node:latest
# ENV SOME=3000 <--- THIS IS WORKS, BUT I WANT TO DO IT IN COMPOSE FILE.
WORKDIR /usr/src/app
COPY ./dist/myapp/package.json .
RUN npm install
COPY ./dist/myapp .
EXPOSE 3000
CMD [ "npm", "start" ]
docker-compose.myweb.ecr.yml:
version: '3'
services:
www-app:
# env_file: ../.env
image: 32934544.dkr.ecr.us-east-2.amazonaws.com/www-app:latest
environment:
- SOME=6000
build:
context: ../
dockerfile: ./.docker/Dockerfile
The problem is I got undefined from process.env.SOME. How to fix that?