NASA-AMMOS / MMGIS

Multi-Mission Geographical Information System - Web-based Mapping and Spatial Data Infrastructure for Planetary Science Operations - https://nasa-ammos.github.io/MMGIS/
Apache License 2.0
139 stars 45 forks source link

Installing with docker produces: Database already exists #537

Closed sparkvilla closed 4 months ago

sparkvilla commented 4 months ago

Checked for duplicates

Yes - I've already checked

Describe the bug

I am following the instruction to install the MMGIS platform using docker. I got to the point of docker compose up command. I am getting this output:

❯ docker compose up
[+] Running 2/0
 ⠿ Container mmgis-db-1     Recreated                                                           0.0s
 ⠿ Container mmgis-mmgis-1  Recreated                                                           0.0s
Attaching to mmgis-db-1, mmgis-mmgis-1
mmgis-db-1     | 
mmgis-db-1     | PostgreSQL Database directory appears to contain a database; Skipping initialization
mmgis-db-1     | 
mmgis-db-1     | 2024-04-29 12:17:41.117 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
mmgis-db-1     | 2024-04-29 12:17:41.117 UTC [1] LOG:  listening on IPv6 address "::", port 5432
mmgis-db-1     | 2024-04-29 12:17:41.118 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
mmgis-db-1     | 2024-04-29 12:17:41.132 UTC [21] LOG:  database system was shut down at 2024-04-29 12:15:41 UTC
mmgis-db-1     | 2024-04-29 12:17:41.135 UTC [1] LOG:  database system is ready to accept connections
mmgis-mmgis-1  | 
mmgis-mmgis-1  | > mmgis@2.11.0 start:prod
mmgis-mmgis-1  | > node scripts/init-db.js && cross-env NODE_ENV=production node scripts/server.js
mmgis-mmgis-1  | 
 info   Database db already exists. Nothing to do...
 infrastructure_error   Unable to connect to the database.
mmgis-mmgis-1  |    Caller: connection
mmgis-mmgis-1  |    Error: ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:5432
mmgis-mmgis-1  |     at Client._connectionCallback (/usr/src/app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:131:24)
mmgis-mmgis-1  |     at Client._handleErrorWhileConnecting (/usr/src/app/node_modules/pg/lib/client.js:327:19)
mmgis-mmgis-1  |     at Client._handleErrorEvent (/usr/src/app/node_modules/pg/lib/client.js:337:19)
mmgis-mmgis-1  |     at Connection.emit (node:events:518:28)
mmgis-mmgis-1  |     at Socket.reportStreamError (/usr/src/app/node_modules/pg/lib/connection.js:58:12)
mmgis-mmgis-1  |     at Socket.emit (node:events:518:28)
mmgis-mmgis-1  |     at emitErrorNT (node:internal/streams/destroy:169:8)
mmgis-mmgis-1  |     at emitErrorCloseNT (node:internal/streams/destroy:128:3)
mmgis-mmgis-1  |     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
mmgis-mmgis-1  |   parent: Error: connect ECONNREFUSED 127.0.0.1:5432
mmgis-mmgis-1  |       at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16) {
mmgis-mmgis-1  |     errno: -111,
mmgis-mmgis-1  |     code: 'ECONNREFUSED',
mmgis-mmgis-1  |     syscall: 'connect',
mmgis-mmgis-1  |     address: '127.0.0.1',
mmgis-mmgis-1  |     port: 5432
mmgis-mmgis-1  |   },
mmgis-mmgis-1  |   original: Error: connect ECONNREFUSED 127.0.0.1:5432
mmgis-mmgis-1  |       at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16) {
mmgis-mmgis-1  |     errno: -111,
mmgis-mmgis-1  |     code: 'ECONNREFUSED',
mmgis-mmgis-1  |     syscall: 'connect',
mmgis-mmgis-1  |     address: '127.0.0.1',
mmgis-mmgis-1  |     port: 5432
mmgis-mmgis-1  |   }
mmgis-mmgis-1  | }
 info   Failed.| 

Is there someone that can help me with that? My host OS is Ubuntu 22.04

What did you expect?

I expected to run the containers

Reproducible steps

1.
2.
3.
...

Environment

- Version of this software [e.g. vX.Y.Z]
- Operating System: [e.g. MacOSX with Docker Desktop vX.Y]
...
tariqksoliman commented 4 months ago

Hi and interesting. Any chance you already have postgresql on your machine and are pointing to the same data directory? Maybe try changing the DB_NAME in your .env to point to another database other than db. I would also try entering the mmgis docker container and check the connection to postgres from there with the values you have in the .env. Something like:

docker ps
docker exec -it {mycontainer} bash
apt install postgresql-client
psql -h {host} -U {username} -p
sparkvilla commented 4 months ago

@tariqksoliman Thank you for your help.

I checked whether postgresql db is already running on my host, and that seems not to be the case.

❯ sudo systemctl status postgresql
Unit postgresql.service could not be found.

I changed DB_NAMEand that did not have any effect. Yet, I tried to enter the mmgis container from another terminal window (after running docker compose up ) and I get:

❯ docker exec -it 80f835b29091 bash
Error response from daemon: Container 80f835b290910343ec73b16b37af4d182983b2b7a7448ee5bf8a5647dbd69494 is restarting, wait until the container is running

This is because the mmgis container keeps restarting.

I share my docker-compose.yml

version: "3"
services:
  mmgis:
    build: .
    depends_on:
      - db
    env_file: .env
    ports:
      - 8888:8888
    restart: on-failure
    volumes:
      - ./Missions:/usr/src/app/Missions
  db:
    image: postgis/postgis:10-2.5-alpine
    env_file: .env
    ports:
      - 5432:5432
    restart: on-failure
    volumes:
      - mmgis-db:/var/lib/postgresql/data
volumes:
  mmgis-db:

and the relevant part of my .env file

# Postgres' default port is 5432
DB_PORT=5432
DB_NAME=db
DB_USER=postgres
DB_PASS=test

not sure what else to try for the moment..

sparkvilla commented 4 months ago

Ok. I find it!!

In the .envfile I had this line:

DB_HOST=localhost

But actually the comment says: # If using docker, DB_HOST is the database container name

So, I rename it to DB_HOST=mmgis-db-1

And now I can connect to the db. Thank you for the support!