docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.18k stars 1.13k forks source link

postgres image (or Docker) ignores updates to .sql files but not .sh files in /docker-entrypoint-initdb.d?? #439

Closed ShiraazMoollatjie closed 6 years ago

ShiraazMoollatjie commented 6 years ago

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

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

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 ('myEmailAddress@gmail.com');

COMMIT;
ShiraazMoollatjie commented 6 years ago

So it turns out that the underlying file system is playing a role here when using Docker Volumes. I have been using a virtualbox vm and the project was sitting on a vboxsf file system. So when attaching a volume in my docker compose scenario(?), it has been attaching to a vboxsf volume this whole time.

When I moved the project from the vboxsf filesystem to something else (whatever my home directory filesystem has, ext4 I think) then updates to the files worked as expected.

https://www.virtualbox.org/ticket/819?cversion=0&cnum_hist=70 is the link for more information

I don't think that this is a postgres image issue anymore, I will close this issue