I am starting up a postgres container using the below shown docker-compose.yml.
After i start the containers, the init scripts creates the schemas and tables. If I log into docker container docker exec -it my_postgres /bin/bash
and run psql, I can see all the tables in the schema.
But if I connect to port 5432 on my local host from a IDE client, login succeeds, I see the database and schema that was created. But donot see any of the tables in the schema.
I am not trying to have persistent data. Rather, I want to create the schema and tables everytime the container starts up and access the database from outside the container.
version: '3.8'
services:
db:
image: postgres
container_name: my_postgres
restart: always
environment:
- POSTGRES_USER=docker_u
- POSTGRES_PASSWORD=xxxx
- TZ=America/New_York
ports:
- 5432:5432
volumes:
- '~/myprojects/tmp/docker/create_user.sql:/docker-entrypoint-initdb.d/1-create_user.sql'
- '~/myprojects/db/events.sql:/docker-entrypoint-initdb.d/2-create_tables.sql'
- '~/myprojects/db/function.close_alert_using_signature.sql:/docker-entrypoint-initdb.d/3-function.close_alert_using_signature.sql'
I get the following error on docker-compose console
my_postgres | 2023-03-20 17:56:50.230 EDT [146] STATEMENT: select * from sentinus.rest_events
my_postgres | 2023-03-20 17:57:01.409 EDT [146] ERROR: relation "sentinus.rest_events" does not exist at character 15