Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker file postgres initial schemas not executed

I updated my docker file to version 3 but now the inicial schemas are not being created. i already tried with a different volume I run it with : docker-compose -f docker-compose.yml up

version: '3'
services:
  db-service:
    image: postgres:11.2
    volumes:
      - ./dbscripts/:/docker-entrypoint-initdb.d/
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=sample
    ports:
      - 5432:5432
like image 655
John Avatar asked Jul 22 '26 13:07

John


1 Answers

Check these 2 things:


The init scripts are triggered only on the first deploy. On the subsequent docker-compose ups you probably see as well on the logs the following message:

db_1  | PostgreSQL Database directory appears to contain a database; Skipping initialization

To force the re-initialization, you can wipe the data volume(This will delete the entries, not only the schema).
To find the path, simply docker inspect <postgres-container-id> and look for the HostConfig.Binds


The script executes till the first type "longvarbinary" does not exist error. You will need to fix this.

db-service_1  | CREATE TABLE
db-service_1  | 2020-07-26 19:29:34.121 UTC [68] ERROR:  type "longvarbinary" does not exist at character 68

I opened a console in the postgres container and your sample database is there, as well as a table that is created before the .sql error occurs in the script:

docker exec -ti 22b0bb87561f sh
# psql -U postgres
psql (11.2 (Debian 11.2-1.pgdg90+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 | 
 sample    | 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
(4 rows)

postgres=# \c sample
You are now connected to database "sample" as user "postgres".
sample=# \dt
                List of relations
 Schema |         Name         | Type  |  Owner   
--------+----------------------+-------+----------
 public | oauth_client_details | table | postgres
(1 row)

like image 175
Neo Anderson Avatar answered Jul 25 '26 05:07

Neo Anderson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!