Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ShiraazMoollatjie opened this issue May 2, 2018 · 1 comment

Comments

@ShiraazMoollatjie
Copy link

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 an init.sh and init.sql file. The sql script can be anything, but below is what I used. The init.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 by docker-compose up
  • You will see in the logs that the updated init.sh script runs and an outdated version of init.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;
@ShiraazMoollatjie
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant