Hello I'm trying to make my docker compose work, but I have the following error:
Step 13/15 : COPY .env . COPY failed: stat /var/lib/docker/tmp/docker-builder209795817/.env: no such file or directory
I'm not able to find solutions or imagine what I can do to solve this
code:
DockerCompsoe:
version: "3.7"
services:
db:
image: postgres
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: emasa
volumes:
- ./pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
web:
image: emasapg
depends_on:
- dbs
ports:
- "4000:4000"
DockerFile:
FROM node as builder
WORKDIR usr/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM node
WORKDIR usr/app
COPY package*.json ./
RUN npm install --production
COPY --from=builder /usr/app/dist ./dist // I GOT PROBLEM HERE
COPY ormconfig.docker.json ./ormconfig.json
COPY .env .
expose 4000
CMD node dist/src/index.js
My package.json:
{
"name": "back-end",
"version": "0.0.1",
"description": "Awesome project developed with TypeORM.",
"scripts": {
"dev:server": "ts-node-dev --respawn --transpileOnly src/index.ts",
"build": "tsc -b"
},
"devDependencies": {
"@types/express": "^4.17.3",
"@types/node": "^13.9.1",
"typescript": "^3.8.3"
},
"dependencies": {
"apollo-server-express": "^2.11.0",
"express": "^4.17.1",
"graphql": "^14.6.0",
"pg": "^7.3.0",
"reflect-metadata": "^0.1.13",
"ts-node": "^8.6.2",
"typeorm": "0.2.24"
}
}
my ormconfig:
{
"type": "postgres",
"host": "db",
"port": 5432,
"username": "postgres",
"password": "postgres",
"database": "emasa",
"synchronize": true,
"logging": false,
"entities": ["src/entity/**/*.ts"],
"migrations": ["src/migration/**/*.ts"],
"subscribers": ["src/subscriber/**/*.ts"],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "src/migration",
"subscribersDir": "src/subscriber"
}
}
and this is my folders structures:
The error appears because there is no .env file and no dist folder.
First of all you need to create a .env file at the root of your project structure in order to provide the needed environment variables (e.g. like name, host, port, password and user of your database connection). Next run npm run build
to build your project, which will create the dist folder (see your tsconfig.json).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With