OR-Mapper JPA docker run sql scripts
Context
In exercise OR-Mapper_JPA, running the sql scripts with the provided docker command fail. The relevant section of the documentation is https://gitlab.ost.ch/db/dateng/-/tree/master/OR-Mapper_JPA#datenbank-bank
Summary
When executing the snippet:
docker-compose
--file Helpers/docker-compose.yml
--project-name dataeng
--project-directory .
run postgres
psql
-h postgres
-U postgres
-v ON_ERROR_STOP=on
-f /src/Databases/bank/0_runAllScripts.sql
The following is displayed:
$ docker-compose --file Helpers/docker-compose.yml --project-name dataeng --project-directory . run postgres psql -h postgres -U postgres -v ON_ERROR_STOP=on -f /src/Databases/bank/0_runAllScripts.sql
WARNING: The HOME variable is not set. Defaulting to a blank string.
Creating dataeng_postgres_run ... done
psql: could not connect to server: Connection refused
Is the server running on host "postgres" (10.0.1.8) and accepting
TCP/IP connections on port 5432?
Steps to reproduce
Follow the documentation using docker-compose to run postgres server
What is the current issue behavior?
$ docker-compose --file Helpers/docker-compose.yml --project-name dataeng --project-directory . run postgres psql -h postgres -U postgres -v ON_ERROR_STOP=on -f /src/Databases/bank/0_runAllScripts.sql
WARNING: The HOME variable is not set. Defaulting to a blank string.
Creating dataeng_postgres_run ... done
psql: could not connect to server: Connection refused
Is the server running on host "postgres" (10.0.1.8) and accepting
TCP/IP connections on port 5432?
We found that the ip for "postgres" does not point to the running postgres server but to the "dataeng_postgres_run" container, causing it to connect to itself, where no sql server is running.
What is the expected correct behavior?
The script ought to connect to the running postgres server and execute the script. We achieved this by manually adding the correct/current IP to the psql command...
Relevant logs and/or screenshots
$ docker-compose --file Helpers/docker-compose.yml --project-name dataeng --project-directory . run postgres psql -h postgres -U postgres -v ON_ERROR_STOP=on -f /src/Databases/bank/0_runAllScripts.sql
WARNING: The HOME variable is not set. Defaulting to a blank string.
Creating dataeng_postgres_run ... done
psql: could not connect to server: Connection refused
Is the server running on host "postgres" (10.0.1.8) and accepting
TCP/IP connections on port 5432?
Possible fixes
It should be possible to use docker exec
or a similar command to run the scripts directly in the already running postgres container.