1 Introduction In the article "Start PostgreSQL with Docker and Recommend Several Connection Tools", we introduced how to start 2 Two solutions One solution is to put Put the The following is an example of #!/bin/bash set -e set -u function create_user_and_database() { local database=$1 echo " Creating user and database '$database'" psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL CREATE USER $database; CREATE DATABASE $database; GRANT ALL PRIVILEGES ON DATABASE $database TO $database; EOSQL } if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES" for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do create_user_and_database $db done echo "Multiple databases created" fi The following is an example of a CREATE USER pkslowuser; CREATE DATABASE logdata; GRANT ALL PRIVILEGES ON DATABASE logdata TO pkslowuser; CREATE DATABASE orderdata; GRANT ALL PRIVILEGES ON DATABASE orderdata TO pkslowuser; CREATE DATABASE userdata; GRANT ALL PRIVILEGES ON DATABASE userdata TO pkslowuser; 3 Packaging and startup Prepare FROM postgres:10 COPY src/main/resources/create-multiple-postgresql-databases.sh /docker-entrypoint-initdb.d/ COPY src/main/resources/create-multiple-postgresql-databases.sql /docker-entrypoint-initdb.d/ Start as follows: docker run -itd \ --name pkslow-postgres \ -e POSTGRES_MULTIPLE_DATABASES=db1,db2 \ -e POSTGRES_USER=pkslow \ -e POSTGRES_PASSWORD=pkslow \ -p 5432:5432 \ pkslow/postgresql-multiple-databases:1.0-SNAPSHOT After successful startup, the following database will be created: db1,db2, logdata,orderdata,userdata 4 ConclusionThis is a solution used in the development and testing phase. In fact, putting the database in a container is not a good choice. Please check the code: https://github.com/LarryDpk/pkslow-samples This concludes this article about creating multiple databases when starting PostgreSQL with Docker. For more information about starting PostgreSQL with Docker, please search for previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
>>: HTML4.0 element default style arrangement
In daily development tasks, we often use MYSQL...
Table of contents Early creation method Factory P...
Question 1: How do you instruct the browser to dis...
Table of contents topic analyze Objects of use So...
introduction If you are familiar with using JDBC ...
Preface When using Docker in a production environ...
Table of contents What is a listener in vue Usage...
<br />I just saw the newly revamped ChinaUI....
Step 1: yum install httpd -y #Install httpd servi...
This article example shares the specific code of ...
Table of contents 1. Overview 2. Use docker to de...
The default varchar type in MySQL is case insensi...
This article records the installation and configu...
Table of contents Preface Scenario Analysis Summa...
While the paperless world has not yet emerged, mo...