Created
February 18, 2021 14:34
-
-
Save Itsindigo/e854d6340fe666285e75eb41dea123ed to your computer and use it in GitHub Desktop.
MySQL / Postgres Docker Container Init DBs Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3" | |
services: | |
a-postgres-container: | |
image: postgres:12 | |
ports: | |
- ${DB_PORT_SOME_EXTERNAL_BIND:-5432}:5432 | |
environment: | |
- POSTGRES_HOST=postgres | |
- POSTGRES_USER=my_user | |
- POSTGRES_PASSWORD=my_password | |
entrypoint: sh -c " | |
echo \"psql -v ON_ERROR_STOP=1 --username my_user --dbname postgres <<-EOSQL\n | |
CREATE DATABASE some_app_database;\n | |
GRANT ALL PRIVILEGES ON DATABASE some_app_database TO my_user;\n | |
CREATE DATABASE some_app_database_test;\n | |
GRANT ALL PRIVILEGES ON DATABASE some_app_database_test TO my_user;\nEOSQL\" > /docker-entrypoint-initdb.d/init-databases.sh; | |
docker-entrypoint.sh postgres" | |
a-mysql-container: | |
image: mysql:5.7 | |
ports: | |
- ${DB_PORT_SOME_EXTERNAL_BIND:-3306}:3306" | |
environment: | |
- MYSQL_USER=my_user | |
- MYSQL_PASSWORD=my_password | |
- MYSQL_ROOT_PASSWORD=my_password | |
entrypoint: | |
sh -c " | |
echo 'CREATE DATABASE IF NOT EXISTS `some_app_database`; CREATE DATABASE IF NOT EXISTS `some_app_database_test`; GRANT ALL PRIVILEGES ON `some_app_database`.* TO my_user; GRANT ALL PRIVILEGES ON `some_app_database_test`.* TO my_user;' > /docker-entrypoint-initdb.d/init.sql; | |
/usr/local/bin/docker-entrypoint.sh --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment