Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

Why Your Docker-Compose Fails to Create a Custom PostgreSQL Database

Автор: vlogize

Загружено: 2025-04-16

Просмотров: 32

Описание:

Discover how to resolve the issue of your custom database not being created in Docker-Compose for PostgreSQL, with step-by-step guidance.
---
This video is based on the question https://stackoverflow.com/q/72517169/ asked by the user 'AlexanderKondrat' ( https://stackoverflow.com/u/16174212/ ) and on the answer https://stackoverflow.com/a/72517244/ provided by the user 'Hans Kilian' ( https://stackoverflow.com/u/3924803/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.

Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Why database is not create when docker-compose up?

Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.

If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
Why Your Docker-Compose Fails to Create a Custom PostgreSQL Database

When working with Docker to run PostgreSQL, you may encounter a common problem: your custom database fails to create, leaving you with just a default database named postgres. This situation can be frustrating, especially when you have high hopes for your database setup. In this guide, we will explore this issue, why it occurs, and how to effectively solve it.

The Problem Explained

Imagine you’re trying to set up PostgreSQL using Docker and docker-compose, but after running docker-compose up -d --build, you find that only the default postgres database is created. Your custom configurations and scripts seem to have no effect. This is a common concern that can trip up many developers, especially those new to Docker and container orchestration.

What You Did

Here’s a brief overview of your setup:

Dockerfile to build the PostgreSQL image.

docker-compose.yml to define your PostgreSQL service settings, including volume mappings and environment variables for the database configuration.

An initialization script (create_extension.sql) intended to run when the database is created.

An .env file that holds sensitive information like database names and passwords.

You expected that your provided environment settings and scripts would create your custom database and needed extensions, but instead, they were ignored.

Understanding the Solution

The key to solving this issue lies in understanding how PostgreSQL initialization works within Docker containers. The PostgreSQL image only uses the provided environment variables and initialization scripts when it detects that there is no existing database on startup. Thus, if a volume previously exists (like postgres_data in your setup), PostgreSQL will skip the initialization steps, leading to the behavior you're experiencing.

Steps to Resolve the Issue

Here’s a clear walkthrough of how to get your custom database created successfully:

Delete the Existing Volume: Since the existing volume holds a database, you need to remove it.

You can do this with the command:

[[See Video to Reveal this Text or Code Snippet]]

Replace <your_project_name> with the actual name of your Docker project.

Rebuild and Restart the Container: After deleting the volume, run the docker-compose command again.

[[See Video to Reveal this Text or Code Snippet]]

This command rebuilds the container and ensures it starts fresh without an existing database.

Check Your Custom Database: After running the above command, check to see if your custom database (mydb in this case) has been created along with the specified extensions defined in your SQL scripts.

Verification

Finally, verify your setup by connecting to your PostgreSQL instance:

[[See Video to Reveal this Text or Code Snippet]]

Look for your custom database and confirm that the extensions are correctly applied.

Conclusion

If your Docker setup for PostgreSQL isn’t behaving as expected, remember that the presence of an existing database can interfere with the initialization process. By deleting the existing volume and restarting your setup, you can allow your custom configurations to take effect. This solution not only applies to PostgreSQL but can be a handy approach for other services using Docker with similar initialization logic.

Happy coding, and may your databases be ever in your favor!

Why Your Docker-Compose Fails to Create a Custom PostgreSQL Database

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

Docker Compose with .NET 8, PostgreSQL, and Redis (step by step)

Docker Compose with .NET 8, PostgreSQL, and Redis (step by step)

Docker Image BEST Practices - From 1.2GB to 10MB

Docker Image BEST Practices - From 1.2GB to 10MB

DNA Pattern Recognition | Leetcode 3475 | Crack SQL Interviews

DNA Pattern Recognition | Leetcode 3475 | Crack SQL Interviews

Внутренняя архитектура PostgreSQL: объяснение

Внутренняя архитектура PostgreSQL: объяснение

Docker за 20 минут

Docker за 20 минут

Новое расширение Claude для Chrome: секретное оружие, которое должен использовать каждый

Новое расширение Claude для Chrome: секретное оружие, которое должен использовать каждый

СРОЧНО отключи это в Telegram! Защити себя ПРОСТЫМ и ЗАКОННЫМ способом

СРОЧНО отключи это в Telegram! Защити себя ПРОСТЫМ и ЗАКОННЫМ способом

Сисадмины больше не нужны? Gemini настраивает Linux сервер и устанавливает cтек N8N. ЭТО ЗАКОННО?

Сисадмины больше не нужны? Gemini настраивает Linux сервер и устанавливает cтек N8N. ЭТО ЗАКОННО?

How to create a docker-compose setup with PostgreSQL and pgAdmin4

How to create a docker-compose setup with PostgreSQL and pgAdmin4

Typst: Современная замена Word и LaTeX, которую ждали 40 лет

Typst: Современная замена Word и LaTeX, которую ждали 40 лет

Run Postgres in a Docker Container (Easiest PostgreSQL Setup)

Run Postgres in a Docker Container (Easiest PostgreSQL Setup)

Чем ОПАСЕН МАХ? Разбор приложения специалистом по кибер безопасности

Чем ОПАСЕН МАХ? Разбор приложения специалистом по кибер безопасности

Что скрывают в вашем номере отеля? Реальный случаи слежки..

Что скрывают в вашем номере отеля? Реальный случаи слежки..

Bluetooth-шпионаж: Как ваши гаджеты следят за вами? OSINT-расследование

Bluetooth-шпионаж: Как ваши гаджеты следят за вами? OSINT-расследование

Microsoft begs for mercy

Microsoft begs for mercy

БЕЛЫЕ СПИСКИ: какой VPN-протокол справится? Сравниваю все

БЕЛЫЕ СПИСКИ: какой VPN-протокол справится? Сравниваю все

Bill Gates STUNNED as Windows 12 Faces MASSIVE Backlash Before Launch!

Bill Gates STUNNED as Windows 12 Faces MASSIVE Backlash Before Launch!

Django PostgreSQL | Creating a new PostgreSQL Docker Container (docker-compose)

Django PostgreSQL | Creating a new PostgreSQL Docker Container (docker-compose)

Сетевые технологии Docker — это просто ЧУДО!! (вам НУЖНО это изучить)

Сетевые технологии Docker — это просто ЧУДО!! (вам НУЖНО это изучить)

docker: secrets at build time! (intermediate) anthony explains #544

docker: secrets at build time! (intermediate) anthony explains #544

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: infodtube@gmail.com