I have a project that currently use the official postgres docker image that I’m changing to building my own image using dockerTools.buildImage
to get more control over what is put inside the image and because I prefer using nix over Dockerfiles.
The problem I have is that the following entrypoint fails:
#!${stdenv.shell}
${coreutils}/bin/id
echo "PGDATA: $PGDATA"
${coreutils}/bin/ls -la /bin/postgres
${file}/bin/file /bin/postgres
${coreutils}/bin/ls -la /bin/initdb
${file}/bin/file /bin/initdb
postgres -V
initdb -U ${user}
Where contents = [ postgresql_11 ];
is set. The result is the following output:
uid=999(postgres) gid=999(postgres) groups=999(postgres)
PGDATA: /postgres/data
-r-xr-xr-x 1 root root 8182360 Jan 1 1970 /bin/postgres
/bin/postgres: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27/lib/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, not stripped
-r-xr-xr-x 1 root root 291 Jan 1 1970 /bin/initdb
/bin/initdb: a /nix/store/cinw572b38aln37glr0zb8lxwrgaffl4-bash-4.4-p23/bin/bash -e script, ASCII text executable
postgres (PostgreSQL) 11.2
no data was returned by command ""/bin/postgres" -V"
The program "postgres" is needed by initdb but was not found in the
same directory as "/bin/initdb".
As you can see:
-
postgres
is in the same directory asinitdb
-
postgres
is an executable file -
postgres
has execution permissions for anyone - When run
postgres
produces the correct version
The interesting thing is that if I would put the initdb command in runAsRoot
instead, so that it is done while the image is being created inside the VM-based builder, I encounter the same problem.
If I use the specific package that is put inside the Docker image and run it directly on my host, it works as expected.
I can’t for the life of me understand why this happens. I even looked at the source code of initdb and strace. The only thing I see is that “postgres -V” is being run but the receiving end of the pipe is just empty.
I’ve tried Postgres 9.6 with the same result.
Here’s the specific code in initdb that does the check that fails:
- postgres/initdb.c at aed967d697de19a78a653926c72604f9b04c3b1e · postgres/postgres · GitHub
- postgres/exec.c at aed967d697de19a78a653926c72604f9b04c3b1e · postgres/postgres · GitHub
- postgres/exec.c at aed967d697de19a78a653926c72604f9b04c3b1e · postgres/postgres · GitHub
I can provide a fully reproducible script if anyone is interested in recreating the problem locally.
Any ideas or suggestions are greatly appreciated!