docker-compose.yml如下:文章来源:https://www.toymoban.com/news/detail-709013.html
version: '3'
services:
postgres:
image: postgres:15.4
healthcheck:
test: [ "CMD", "pg_isready", "-q", "-d", "postgres", "-U", "root" ]
timeout: 45s
interval: 10s
retries: 10
restart: always
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=123456
- APP_DB_USER=user01
- APP_DB_PASS=123456
- APP_DB_NAME=my_app
volumes:
- ./db:/docker-entrypoint-initdb.d/
- /data/postgres:/var/lib/postgresql/data
ports:
- 5432:5432
db\01-init.sh如下文章来源地址https://www.toymoban.com/news/detail-709013.html
#!/bin/bash
set -e
export PGPASSWORD=$POSTGRES_PASSWORD;
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER $APP_DB_USER WITH PASSWORD '$APP_DB_PASS';
CREATE DATABASE $APP_DB_NAME;
GRANT ALL PRIVILEGES ON DATABASE $APP_DB_NAME TO $APP_DB_USER;
\connect $APP_DB_NAME $APP_DB_USER
BEGIN;
CREATE TABLE IF NOT EXISTS event (
id CHAR(26) NOT NULL CHECK (CHAR_LENGTH(id) = 26) PRIMARY KEY,
aggregate_id CHAR(26) NOT NULL CHECK (CHAR_LENGTH(aggregate_id) = 26),
event_data JSON NOT NULL,
version INT,
UNIQUE(aggregate_id, version)
);
CREATE INDEX idx_event_aggregate_id ON event (aggregate_id);
COMMIT;
EOSQL
到了这里,关于PostgreSQL docker compose安装配置的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!