Closed nurked closed 6 years ago
I'm not real experienced in SQL's but the databases in your screenshot appears to be missing the one defined from the ENV POSTGRES_DB=db
and also the postgres
database from the default user postgres
When I run your dockerfile everything seems correct.
$ docker run --rm -d --name postgres_test postgres_test
$ docker exec -it postgres_test bash
bash-4.4# psql -ddb -Uuser
psql (10.4)
Type "help" for help.
db=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
db | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
db=# \dt
List of relations
Schema | Name | Type | Owner
--------+---------+-------+-------
public | account | table | user
public | users | table | user
(2 rows)
db=# SELECT * from account;
id | user_id | balance
----+---------+---------
(0 rows)
Ok, thank you very much @wglambert for the answer. This basically gave me a solution. It's not a postgres issue and postgres is working allright. In fact when I logged in to the container I found all of my tables without any problem.
The thing to blame is heidiSQL program which seems to be unable to display posgtres database structure properly. I connected to the container same way you did it and I was able to see the tables. Then I used pgAdmin III and despite numerous errors I was able to find all my tables.
Darn! Wasted entire day debugging things when there is nothing to debug at all.
Well, at least everything is working fine.
Per the write-up here I should be able to extend the image to init the database on startup. No matter what I do I can't seem to be able to run this init script. According to the logs script starts and all instructions get executed, but there is nothing in the final database once I connect there.
Here is the example:
docker-compose.yaml:
Dockerfile:
One of the SQL scripts (vetted):
Build happens without any problems and once I have it done I can see the startup log:
Once you connect to the database you see empty table:
Currently I have to init the database by other means, but I wanted to be able to use docker-entrypoint-initdb.d