I want to setup some initial tables in docker postgres.
I look at https://stackoverflow.com/a/34753186/72437 , thought it would be straight forward.
docker-compose.yml
version: '2'
services:
postgres:
build:
context: ./postgres
dockerfile: Dockerfile
restart: always
ports:
- "5432:5432"
postgres/postgres.sql
CREATE TABLE my_table (
client_id character varying(36) NOT NULL,
value character varying(255)
);
postgres/Dockerfile
FROM postgres:latest
ENV POSTGRES_DB my_db
ADD postgres.sql /docker-entrypoint-initdb.d/
Then, I execute
- docker-compose build
- docker-compose up
I try to exam my database by
docker ps
docker exec -it bb54abc9be16 bash
root@bb54abc9be16:/# psql -h 127.0.0.1 -U postgres
psql (10.1)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
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
(3 rows)
Seem like my_db
DB and my_table
table are not created.
May I know what thing I had missed out?