docker-postgres-windows icon indicating copy to clipboard operation
docker-postgres-windows copied to clipboard

could not open file "C:\.pgpass" for reading: No such file or directory

Open fzumstein opened this issue 6 years ago • 6 comments

I am on Windows Server 2019 with LCOW. When I leave away the password, the docker container comes up correctly:

docker run --name some-postgres -d stellirin/postgres-windows

However, when I include the password, then I get the following error, any ideas?

docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d stellirin/postgres-windows

Error:

$ docker logs some-postgres
Access is denied.
The files belonging to this database system will be owned by user "ContainerUser".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".

Data page checksums are disabled.
initdb: could not open file "C:\.pgpass" for reading: No such file or directory
authMethod: md5
The system cannot find the drive specified.
PostgreSQL init process complete; ready for start up.

fzumstein avatar Nov 06 '19 16:11 fzumstein

Oof it's been over a year since I wrote this and I'm not exactly an expert at Windows CMD!

The relevant code is at: https://github.com/stellirin/docker-postgres-windows/blob/master/docker-entrypoint.cmd#L67

The file is required because the equivalent code in the original docker-entrypoint.sh uses features of UNIX shell not available to CMD. See: https://github.com/docker-library/postgres/blob/master/12/docker-entrypoint.sh#L75

The behaviour you see suggests that the --pwfile="C:\.pgpass" is correctly set but the echo command to create the file is not working. It definitely worked in the past as I tested this locally and the software I use at work was able to connect to the database.

C:\.pgpass might not be the best location for this file, is it possible some permissions in the Windows container environment got tightened up?

I'll try to take a look this weekend.

stellirin avatar Nov 07 '19 17:11 stellirin

Thanks for your response! In the meantime I could make the original Linux based image work by using this hack: https://github.com/puppetlabs/pupperware/blob/master/README-windows.md#set-the-volumes-directory-permissions together with a named volume (host mounting wouldnt work). So feel free to close this issue.

fzumstein avatar Nov 07 '19 18:11 fzumstein

Glad you found a solution that works for you! I'll probably take a look anyway as I'm behind the latest releases. But most of my motivations for this image have disappeared since the release of Docker for WSL2.

stellirin avatar Nov 07 '19 18:11 stellirin

I'll need to look into that, too, yes. Currently doing LCOW via git bash (which also works great).

On Thu, 7 Nov 2019, 19:09 Adam Farden, [email protected] wrote:

Glad you found a solution that works for you! I'll probably take a look anyway as I'm behind the latest releases. But most of my motivations for this image have disappeared since the release of Docker for WSL2.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/stellirin/docker-postgres-windows/issues/2?email_source=notifications&email_token=AARJDIB5DUVNDFZNAJIJS4LQSRKVFA5CNFSM4JJX2C72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDNJXVQ#issuecomment-551197654, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARJDIDH4K6GQA36VZAIWXLQSRKVFANCNFSM4JJX2C7Q .

fzumstein avatar Nov 07 '19 18:11 fzumstein

So I updated the images and ran a quick test of v12 and all works OK here on the latest Windows 10 Pro.

Right now I can only imagine that your issue is caused by stricter permissions on Windows Server 2019.

I guess I could look at moving this file to the TEMP folder? There's no real reason for this to be written as C:\.pgpass

The files belonging to this database system will be owned by user "ContainerUser".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory C:/pgsql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... windows
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Belgrade
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
ok


Success. You can now start the database server using:

    pg_ctl -D ^"C^:^\pgsql^\data^" -l logfile start

authMethod: md5
The system cannot find the drive specified.
waiting for server to start.... done
server started
CREATE DATABASE
waiting for server to shut down.... done
server stopped
PostgreSQL init process complete; ready for start up.

stellirin avatar Nov 10 '19 11:11 stellirin

OK, that's possible. Also possible that there's a difference between Docker EE and Docker Desktop (which I assume you use).

fzumstein avatar Nov 10 '19 19:11 fzumstein