Add .env.example in dist folder during docker compose up

Viewed 456

I want to generate an .env and and an .env.example file and push it to the docker image during the docker build with Dockerfile. The problem is that the .env.example file is not copied to the docker image. I think it works with the normal env, because I copy the env.production and save it as an env. However, I am using node.js and typescript. Most people know that there is a way to use env viriables in the code by generating an env.d.ts and env.example. During docker compose i am getting unfortunately that error.

no such file or directory, open '.env.example'

apparently the env.example is not copied to the dist folder. I need this one though.

Dockerfile

# stage 1 building the code
FROM node as builder
WORKDIR /usr/app
COPY package*.json ./
RUN npm install
COPY . .
COPY .env.production .env
RUN npm run build
COPY .env.example ./dist


# stage 2
FROM node
WORKDIR /usr/app
COPY package*.json ./
RUN npm install --production

COPY --from=builder /usr/app/dist ./dist

COPY ormconfig.docker.json ./ormconfig.json


EXPOSE 4000
CMD node dist/index.js

.dockerignore

node_modules

docker-compose.yaml

version: "3.7"
services:
  db:
    image: postgres
    environment:
        POSTGRES_PASSWORD: postgres
        POSTGRES_USER: postgres
        POSTGRES_DB: postgres

    volumes:
      - ./pgdata:/var/lib/postgresql/data
    ports:
      - "5432:5432"
  web:
    build:
      context: ./
      dockerfile: ./Dockerfile
    depends_on:
      - db
    ports:
      - "4000:4000"
    volumes:
      - ./src:/src

Could somebody please help me !

0 Answers
Related