How to extend postgres image with separate layers and separate data?

  • i have my base image peterducai/aidb which extends postgres:latest
  • there is /docker-entrypoint-initdb.d/1_aidb_deploy.sql which creates tables and fills country table with data

now i want to create new image xdb which extends peterducai/aidb with dockerfile like

FROM peterducai/aidb:latest

COPY 2_idb_pannet_data.sql /docker-entrypoint-initdb.d/2_extended_data.sql

but when i run xdb

sudo docker run -it --name xdbv2 -p 5432:5432 -e POSTGRES_PASSWORD=post123 -d xdb:latest

i dont see execution of /docker-entrypoint-initdb.d/2_extended_data.sql

2018-05-17 12:16:13.800 UTC [41] LOG:  database system was shut down at 2018-05-17 12:16:13 UTC
2018-05-17 12:16:13.807 UTC [40] LOG:  database system is ready to accept connections
 done
server started
CREATE DATABASE

CREATE ROLE


/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/1_aidb_deploy.sql
GRANT
CREATE SCHEMA
CREATE TABLE
COMMENT
CREATE TABLE
...
CREATE TABLE
INSERT 0 239


2018-05-17 12:16:15.022 UTC [40] LOG:  received fast shutdown request
waiting for server to shut down....2018-05-17 12:16:15.025 UTC [40] LOG:  aborting any active transactions
2018-05-17 12:16:15.029 UTC [40] LOG:  worker process: logical replication launcher (PID 47) exited with exit code 1
2018-05-17 12:16:15.029 UTC [42] LOG:  shutting down
2018-05-17 12:16:15.076 UTC [40] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2018-05-17 12:16:15.152 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2018-05-17 12:16:15.152 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2018-05-17 12:16:15.156 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2018-05-17 12:16:15.175 UTC [77] LOG:  database system was shut down at 2018-05-17 12:16:15 UTC
2018-05-17 12:16:15.187 UTC [1] LOG:  database system is ready to accept connections

What should be proper way to call extra sql that is separated from original aidb?

thanks for any suggestions

sorted out… only issue is that all images have to be removed and rebuild… otherwise you won’t see change. Now it’s working as it is.