I have a question. I am pretty new to docker, so what I am trying to do is create a docker-compose file that on compose command will also create the database. Problem is that does not create DB as I ask it nicely. So my docker-compose looks like:
version: '3'
services:
db:
image: postgres:latest
restart: always
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: 'postgres'
volumes:
- database_data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
volumes:
database_data:
driver: local
And when I start docker-compose up in log I can see
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
db_1 | 2020-01-13 11:14:36.259 UTC [1] LOG: starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2020-01-13 11:14:36.259 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2020-01-13 11:14:36.260 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2020-01-13 11:14:36.264 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2020-01-13 11:14:36.277 UTC [29] LOG: database system was shut down at 2020-01-13 11:10:57 UTC
db_1 | 2020-01-13 11:14:36.280 UTC [1] LOG: database system is ready to accept connections
In my init SQL there is only 1 line:
CREATE DATABASE "MyDataBase";
As I list DB is Postgres container my DB is nowhere to be found. What could be the source root of this problem?