Having problems with docker-compose in dev mode

Hello, guys. I've been struggling for about 6 hours and I can't figure out what's happening with my docker-compose.

Here is the deal, I have a docker-compose base file, one docker-compose.dev and one docker-compose.prod file. When I execute the production docker-compose, everything works perfectly, but in development the postgres container says that my database doesn't exist. Here are the files.

“`

Dockerfile

FROM node:12.10-alpine

WORKDIR /usr/app

COPY package*.json ./

RUN apk add –no-cache bash

RUN npm install

RUN if [ "$NODE_ENV" = "development" ]; then npm install –unsafe-perm; else npm install –only=production; fi

COPY . .

EXPOSE 4000

CMD ["npm", "start"] “`

“`

docker-compose.yml

version: '3'

services: server: build: . ports: – '${PORT}:${PORT}' depends_on: – db networks: – webnet

db: image: postgres:12-alpine ports: – '5432:5432' networks: – webnet volumes: – ./db-data:/var/lib/postgresql/data

networks: webnet: “`

“`

docker-compose.prod.yml

version: '3'

services: server: container_name: PROD_SERVER restart: always env_file: – .env command: ['.bin/wait-for-it.sh', 'db:5432', '–', 'npm', 'start']

db: container_name: PROD_DB restart: always env_file: – .env environment: POSTGRES_USER: $DB_USER POSTGRES_PASSWORD: $DB_PASSWORD POSTGRES_DB: $DB_NAME volumes: – .db/production/:/var/lib/postgresql/data “`

“`

docker-compose.dev.yml

version: '3'

services: server: container_name: DEV_SERVER env_file: – .env.dev volumes: – ./:/usr/app/ command: ['.bin/wait-for-it.sh', 'db:5432', '–', 'npm', 'run', 'dev']

db: container_name: DEV_DB env_file: – .env.dev environment: POSTGRES_USER: $DB_USER POSTGRES_PASSWORD: $DB_PASSWORD POSTGRES_DB: $DB_NAME volumes: – .db/dev/:/var/lib/postgresql/data “`

“`

.dockerignore

.env .git .gitignore node_modules/ .db/ “`

The error message: ERROR: database "rick-and-morty-db-dev" does not exist

Oh and when I set my .env.dev variables exactly as my production .env variables everything works fine, but is not my intention to use the same database for both dev and production.

“`

.env

APP

NODE_ENV=production PORT=4000

DATABASE

DB_USER=meeseeks [email protected] DB_NAME=rick-and-morty-db DB_HOST=db “`

“`

.env.dev

APP

NODE_ENV=development PORT=4000

DATABASE

DB_USER=meeseeks [email protected] DB_NAME=rick-and-morty-db-dev DB_HOST=db “`

Does anyone know where I'm doing wrong?

submitted by /u/sdq-sts
[link] [comments]
Source: Reddit