PostgreSQL – Docker Postgres is not running the init file in docker-entrypoint-initdb.d

Based on Docker’s Postgres documentation, I can create any *.sql file in /docker-entrypoint-initdb.d and let it run automatically.

I have init.sql contains CREATE DATABASE ronda;

In my docker-compose.yaml, I have

web:
restart: always
build: ./web
expose:
-"8000"
links:
-postgres:postgres
volumes:
-/usr/src/app/static
env_file: .env
command: /usr/local/bin/gunicorn ronda.wsgi:application -w 2 -b :8000

nginx:
restart: always
build: ./nginx/
ports:
-"80:80"
volumes:
-/www/ static
volumes_from:
-web
links:
-web:web

postgres:
restart: always
build: ./postgres/
volumes_from:
-data
ports:
-"5432:5432"

data:
restart: always< br /> build: ./postgres/
volumes:
-/var/lib/postgresql
command: "true"

and my postgres Dockerfi le,

FROM library/postgres

RUN mkdir -p /docker-entrypoint-initdb.d
COPY init.sql /docker -entrypoint-initdb.d/

Running docker-compose build and docker-compose works normally, but the database ronda is not created.

If the initialization requirement is only to create ronda mode, then you can use the POSTGRES_DB environment variable described in 07GR.

docker-compose.yml of postgres service The location of the file will be:

postgres:
restart: always
build: ./postgres/
volumes_from:
- data
ports:
-"5432:5432"
environment:
POSTGRES_DB: ronda

In addition, do not use restart: always for your data container, because This container does not run any services (just the true command). Doing so basically tells Docker to run the true command in an infinite loop.

Based on Docker’s Postgres documentation, I can find Create any *.sql file in /docker-entrypoint-initdb.d and let it run automatically.

I have init.sql contains CREATE DATABASE ronda;

In my In the docker-compose.yaml, I have

web:
restart: always
build: ./web
expose:
-"8000"
links:
-postg res:postgres
volumes:
-/usr/src/app/static
env_file: .env
command: /usr/local/bin/gunicorn ronda.wsgi:application- w 2 -b :8000

nginx:
restart: always
build: ./nginx/
ports:
-"80:80"< br /> volumes:
-/www/static
volumes_from:
-web
links:
-web:web

postgres:
restart: always
build: ./postgres/
volumes_from:
-data
ports:
-"5432:5432"
< br />data:
restart: always
build: ./postgres/
volumes:
-/var/lib/postgresql
command: "true"

and my postgres Dockerfile,

FROM library/postgres

RUN mkdir -p /docker-entrypoint-initdb.d< br />COPY init.sql /docker-entrypoint-initdb.d/

Running docker-compose build and docker-compose works normally, but the database ronda is not created.

< p>

If the initialization requirement is only to create the ronda mode, then you can use the POSTGRES_DB environment variable described in 07GR.

Bit of the docker-compose.yml file of the postgres service Will be:

postgres:
restart: always
build: ./postgres/
volumes_from:
-data
ports:< br />-"5432:5432"
environment:
POSTGRES_DB: ronda

In addition, do not use restart: always for your data container, because this container does not run any services (just true command). This basically tells Docker to run the true command in an infinite loop.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 689 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.