Hi,
One of my containers defined in docker-compose.yml file is PostgreSQL database. I am trying to initialize it with .sql script mounted on /docker-entrypoint-initdb.d/
. Docker-compose works fine, but PostgreSQL logs say that my custom name database (guacamole_db) already exists despite it being freshly started container and skips further initialization. Why would that be?
My docker-compose file:
version: '3'
services:
guacd:
container_name: guacamole-guacd
restart: always
image: guacamole/guacd
networks:
- guacamole
guacamole:
container_name: guacamole-guacamole
restart: always
image: guacamole/guacamole
ports:
- "8080:8080"
environment:
- GUACD_HOSTNAME=guacd
- POSTGRESQL_HOSTNAME=database
- POSTGRESQL_DATABASE=${GUACAMOLE_DATABASE}
- POSTGRESQL_USER=${GUACAMOLE_USER}
- POSTGRESQL_PASSWORD=${GUACAMOLE_PASSWORD}
links:
- guacd
- database
networks:
- guacamole
database:
container_name: guacamole-db
restart: always
image: postgres
environment:
- POSTGRES_USER=${GUACAMOLE_USER}
- POSTGRES_DB=${GUACAMOLE_DATABASE}
- POSTGRES_PASSWORD=${GUACAMOLE_PASSWORD}
volumes:
- ./db:/var/lib/postgresql/data:rw
- ./initdb:/docker-entrypoint-initdb.d/:ro
networks:
- guacamole
networks:
guacamole:
driver: bridge
name: guacamole-network
ipam:
driver: default
config:
- subnet: "172.16.30.0/24"
PostgreSQL logs:
server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/01-create-db.sql
psql:/docker-entrypoint-initdb.d/01-create-db.sql:1: ERROR: database "guacamole_db" already exists
2024-08-04 14:37:25.151 UTC [62] ERROR: database "guacamole_db" already exists
2024-08-04 14:37:25.151 UTC [62] STATEMENT: CREATE DATABASE guacamole_db;
PostgreSQL Database directory appears to contain a database; Skipping initialization