'initdb.sql not running in Windows Server 2016 or 2019 in Docker
I installed Docker EE on Windows Server 2016 and 2019. I am spinning up a PostgreSQL container and have an initdb.sql script to initialize the database.
I am using Windows containers, and have tested the script both in docker and docker-compose on Windows 10 in Windows Containers mode. The moment I move it to Windows Server 2016/2019, the database spins up but it does not run the initdb.sql script.
Here is my docker-compose
version: "3"
networks:
localnetwork:
services:
postgres_db:
image: stellirin/postgres-windows:12-1809
restart: unless-stopped
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
volumes:
- .\admin\${ENV:-dev}\dbms\init:C:\docker-entrypoint-initdb.d
ports:
- "5432:5432"
networks:
- localnetwork
How do I get Windows Server 2016/2019 to run the initdb.sql? I cannot docker exec into the container either because it returns Access is denied.
Note, Access is denied is also the case in Windows 10. But I can use Docker Desktop's interface to somehow get into the container to check. Docker EE has no Docker Desktop so this cannot be done.
Solution 1:[1]
this happens when the 1a) data directory for the postgres windows user account does not have access or 1b) you are mounting a docker volume for a directory which is shared between Windows and the docker host from user thomas here
1a. To check permissions on PG_DATA directory run this
// check your dir access
cacls "c:\YourPath\pgdata\dir"
1b) issue if the directory is shared between windows and docker host
docker run -p 54332:5432 -v /tmp/volumes/postgres/log:/var/log/postgresql -v /tmp/volumes/postgres/lib:/var/lib/postgresql mypostgres
2. Also please check, if you have a previous crashed file
Manually remove the postmaster.pid file at \postgres\directory\postmaster.pid and start it again, then it should be fine.
3. From your container you have to export/publish ports to your host with the publish command -p option :
docker run -it -v D:/postgres:/home/dump --name some_postgres -p 5432:5432 -e POSTGRES_PASSWORD=root -d postgres
4. check your fire wall rules
The easiest way to fire up docker with postgres & a nice ref to help you
docker run --name postgres-db -e POSTGRES_PASSWORD=docker -p 5432:5432 -d postgres
Maybe easier to pull a fresh image
Pull down the latest [Postgres image from the Docker Hub][4]
Set the environment variable for password to 'docker'
Create a database, let's call it 'world'
Use a sql dump file to create the table schema and populate it with data
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Transformer |

