Description
I have a docker compose file that looks like this. (postgres:alpine
is currently pointing at v10.3)
version: '3'
services:
webapp:
build: '.'
ports:
- "8000:8000"
networks:
- db
postgres:
image: "postgres:alpine"
environment:
POSTGRES_PASSWORD: "password"
volumes:
- "./scripts:/docker-entrypoint-initdb.d"
networks:
- db
networks:
db:
The scripts folder looks like this:
|- scripts
|-- init.sh
|-- init.sql
The Problem
My workflow for this project is progressive, so I add some SQL initialization data on my host OS, run sudo docker-compose down -v
and then sudo docker-compose up
. I did not update my user to not need the use of sudo for this scenario.
When I update the init.sh
file, then these updates are reflected each time I run docker-compose up
. The init.sql
file however, only remembers the first "version" of this file. Any subsequent updates are ignored when running docker-compose up
.
Things I tried
- Tried
sudo docker-compose up --renew-anon-volumes --force-recreate
which also does not seem to help. - Tried pruning all the volumes with
sudo docker volume prune
. Does not help - Tried pruning the docker system with
sudo docker system prune
- What does work is if I copy the file and it's content to a new file name. Renaming the file does not work
So the question is simply, how do I get content updates of init.sql
to be recognized by my docker compose setup?? I don't understand why changes to init.sh
is picked up but changes to init.sql
are ignored?
How to reproduce
- Add the postgres section to a
docker-compose.yml
file - Add the
scripts
folder with aninit.sh
andinit.sql
file. The sql script can be anything, but below is what I used. Theinit.sh
can have a bunch of echos. - Start container with
docker-compose up
- Make changes to the SQL file (e.g. add more insert statements or move table creation to the top)
- Make changes to the .sh file
- Run
docker-compose down -v
followed bydocker-compose up
- You will see in the logs that the updated
init.sh
script runs and an outdated version ofinit.sql
runs!!
CREATE TABLE CUSTOMER (
ID SERIAL PRIMARY KEY,
NAME VARCHAR(200)
);
SELECT NULL AS "Starting to insert into table CUSTOMER";
INSERT INTO CUSTOMER(NAME) VALUES ('Shiraaz Moollatjie');
CREATE TABLE MAILING_LIST (
ID SERIAL PRIMARY KEY,
NAME VARCHAR(200)
);
SELECT NULL AS "Starting to insert into table MAILING_LIST";
INSERT INTO MAILING_LIST(NAME) VALUES ('[email protected]');
COMMIT;