I’m trying to create 2 docker containers one for dev and one for prod using docker-compose. The two containers should be linked to separate postgres databases.
I tried the following, but it seems to create just one container and one database everytime.

docker-compose.yml

version: "3"
services:
  db:
    image: postgres:latest
    restart: always
    container_name: myinstance-postgres-database
    environment:
      - POSTGRES_USER= dbuser
      - POSTGRES_PASSWORD= dbpass
      - POSTGRES_DB= ProductionDB
   ports:
   - 127.17.0.1:5432:5432
   volumes:
   - myinstance-postgres-db:/var/lib/postgresql/data
  app:
    image: service/platform:latest
    restart: always
    container_name: prod-app
    environment:
      DB_SETUP: "true"
      DB_VENDOR: "postgresql"
      DB_HOST: db
      DB_USER: "dbuser"
      DB_PASSWORD: "dbpass"
      DB_NAME: "ProductionDB"
      DB_WAIT: 10
    ports:
    - 8443:8443
    volumes:
    - myinstance-postgres-git:/usr/local/tomcat/webapps/ROOT/WEB-INF/git
    depends_on:
    - db

volumes:
  myinstance-postgres-db:
  myinstance-postgres-git:

docker-compose.dev.yml

version: "3"
services:
  db:
    image: postgres:latest
    restart: always
    container_name: myinstancedev-postgres-database
    environment:
      - POSTGRES_USER= dbuser
      - POSTGRES_PASSWORD= dbpass
      - POSTGRES_DB= DevDB
   ports:
   - 127.17.0.1:5432:5432
   volumes:
   - myinstancedev-postgres-db:/var/lib/postgresql/data
  app:
    image: service/platform:latest
    restart: always
    container_name: dev-app
    environment:
      DB_SETUP: "true"
      DB_VENDOR: "postgresql"
      DB_HOST: db
      DB_USER: "dbuser"
      DB_PASSWORD: "dbpass"
      DB_NAME: "DevDB"
      DB_WAIT: 10
    ports:
    - 8444:8443
    volumes:
    - myinstancedev-postgres-git:/usr/local/tomcat/webapps/ROOT/WEB-INF/git
    depends_on:
    - db

volumes:
  myinstancedev-postgres-db:
  myinstancedev-postgres-git:

Then I run :

sudo docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d

as a result I have one container which is dev-app and only one database is created.
Any solution ?

Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!