I am new in docker, I've created a dockerfile to launch postgresql image and insert data in a new database.
When I run docker it works well in its container, I can see database and tables created.
But When I try to connect from a client postgres, I see the database created but not tables and we dont know why me and my team..
My DockerFile:
# Dockerfile
FROM postgres:9.6.5
RUN localedef -i fr_FR -c -f UTF-8 -A /usr/share/locale/locale.alias fr_FR.UTF-8
ENV LANG fr_FR.utf8
COPY postgresql.conf /
COPY sql/structure.sql /docker-entrypoint-initdb.d/
My file SQL structure.sql:
CREATE DATABASE DB_ALLOT_BOUCHON_NEW;
GRANT ALL PRIVILEGES ON DATABASE DB_ALLOT_BOUCHON_NEW TO postgres;
CREATE Table IF NOT EXISTS public.SUBSCR (
ID BIGINT NOT NULL,
subscriber_name VARCHAR(100) NOT NULL,
sp_array VARCHAR(100) NOT NULL,
PRIMARY KEY (ID)
);
INSERT INTO SUBSCR (ID, subscriber_name, sp_array) VALUES (1, 'client_1', 'sp_array client_1 client_2');
INSERT INTO SUBSCR (ID, subscriber_name, sp_array) VALUES (2, 'client_2', 'sp_array client_2 client_2');
Command to build and run my dockerfile:
$ docker build -t allot_psql .
$ docker run -d --name custom_psql_running -p 5467:5432 allot_psql -c config_file=postgresql.conf
$ docker logs custom_psql_running
$ docker run -it --rm --link custom_psql_running postgres psql -h custom_psql_running -U postgres
# postgres=# SELECT * from subscr;
Result in my container:
postgres=# select * from subscr;
id | subscriber_name | sp_array
----+-----------------+----------------------------
1 | client_1 | sp_array client_1 client_2
2 | client_2 | sp_array client_2 client_2
(2 rows)
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+--------+-------+----------
public | subscr | table | postgres
(1 row)
postgres=# \d*
Invalid command \d*. Try \? for help.
postgres=# \dt
List of relations
Schema | Name | Type | Owner
--------+--------+-------+----------
public | subscr | table | postgres
(1 row)
postgres=# \d+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+--------+-------+----------+------------+-------------
public | subscr | table | postgres | 8192 bytes |
(1 row)
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+--------+-------+----------
public | subscr | table | postgres
(1 row)
postgres=# \
Invalid command \. Try \? for help.
postgres=# \q
Everything seems to work well but when I use postgresql client, I can see only the database created but not tables inside.
jdbc:postgresql://localhost:5467/db_allot_bouchon_new
username:postgres