SQL files under docker-entrypoint-initdb.d are not executed even if data directory is not initialized
SimoneGiusso opened this issue · comments
According to the documentation running docker compose
on this yaml file:
services:
masterdb:
image: postgres:15.6-alpine
container_name: primary-server
ports:
- 5432:5432
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: psw
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
readonlydb:
image: postgres:15.6-alpine
container_name: hot-standby
ports:
- 5430:5432
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: psw
should initialise:
primary-server with init.sql.
However it does not happen even if the file is correctly mounted:
![Screenshot 2024-04-13 at 22 21 18](https://private-user-images.githubusercontent.com/26305592/322229323-998b708a-41ca-4c02-86e3-bbc9e6569c02.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTU5NTQ1NzAsIm5iZiI6MTcxNTk1NDI3MCwicGF0aCI6Ii8yNjMwNTU5Mi8zMjIyMjkzMjMtOTk4YjcwOGEtNDFjYS00YzAyLTg2ZTMtYmJjOWU2NTY5YzAyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA1MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNTE3VDEzNTc1MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgzOGVlYWNkMzdjMWVkODYyZmJiMDllY2NlYWVhOTUxMzE2ODNlMzFiOThkNzlhMWIxMzRjN2FiODRkYmFlMDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.tutThOGiYBghRpfO37q4DjT1xtEDxBO1J5DEo_v24Es)
Ii tried, to delete/re build the images, delete all the volumes but nothing. The init.sql
script is not executed.
Compose works really hard to keep and re-use volumes between runs (including and especially "anonymous" volumes that aren't specified in the file, but are specified in the images in use), which is probably what you're running into.
Have you tried docker-compose down --volumes
and/or docker-compose up --renew-anon-volumes
?