Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker postgres - Unable to run postgres with --version argument #636

Closed
vsimon opened this issue Nov 19, 2019 · 3 comments · Fixed by #647
Closed

Docker postgres - Unable to run postgres with --version argument #636

vsimon opened this issue Nov 19, 2019 · 3 comments · Fixed by #647
Labels

Comments

@vsimon
Copy link

vsimon commented Nov 19, 2019

In 12.0-alpine, passing the --version argument to docker run worked. This no longer works the same way in 12.1-alpine. I think the arguments are also being passed into pg_ctl in the startup script instead of just postgres which probably won't work in both places with the same arguments.

docker run --rm postgres:12.0-alpine --version

...
PostgreSQL init process complete; ready for start up.

postgres (PostgreSQL) 12.0

docker run --rm postgres:12.1-alpine --version

...
Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

waiting for server to start....2019-11-19 08:35:57.650 GMT [35] FATAL:  --version requires a value
 stopped waiting
pg_ctl: could not start server
Examine the log output.
@wglambert
Copy link

I can reproduce in both Debian and Alpine for 12.1, it seems like it's not quite fully initialized in the latest version before it tries connecting.

$ docker run --rm postgres:12.1 --version       
Unable to find image 'postgres:12.1' locally
12.1: Pulling from library/postgres
8d691f585fa8: Already exists 
c991029393ff: Already exists 
d104c69c9175: Already exists 
0a7fb105514d: Already exists 
c3d11c21cb77: Already exists 
4536342c5414: Already exists 
435bcefd4e05: Already exists 
36b0869ae6f9: Already exists 
673d43b320be: Pull complete 
9e1439b8c21e: Pull complete 
95a87ad93bd5: Pull complete 
789ac3657e75: Pull complete 
c6b8132253d5: Pull complete 
54f8e305bbb5: Pull complete 
Digest: sha256:89a4c55b73a6aa810b23b3924368d190af6e6eb157fa8257d57f362e7eeeb9c6
Status: Downloaded newer image for postgres:12.1
****************************************************
WARNING: No password has been set for the database.
         This will allow anyone with access to the
         Postgres port to access your database. In
         Docker's default configuration, this is
         effectively any other container on the same
         system.

         Use "-e POSTGRES_PASSWORD=password" to set
         it in "docker run".
****************************************************
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
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 /var/lib/postgresql/data -l logfile start

waiting for server to start....2019-11-23 02:05:41.381 GMT [47] FATAL:  --version requires a value
pg_ctl: could not start server
Examine the log output.
 stopped waiting

execing afterwards works normally

$ docker run -d --rm --name postgres postgres:12.1-alpine
c6a70246edb89b766644a727792c000ced4e96407ad2f98cfd558648963c9a09

$ docker exec postgres psql --version
psql (PostgreSQL) 12.1

@yosifkit
Copy link
Member

The cause of this was #496 and specifically this comment noted the change: #496 (comment)

It looks like we may need a want_help function similar to mysql

@loxy
Copy link

loxy commented Mar 2, 2020

Fix #647 causes a problem. When creating multi-stage builds, the "--help" argument was very useful to allow initial data creation. Something like:

FROM postgres:11-alpine AS donor
ENV POSTGRES_DB=mydb
ENV POSTGRES_USER=postgres
ENV POSTGRES_PASSWORD=postgres
ENV PGDATA=/pgdata
COPY "data" "/tmp/"
COPY "dump-restore" "/docker-entrypoint-initdb.d/"
RUN /docker-entrypoint.sh --help

FROM postgres:11-alpine
ENV POSTGRES_DB=mydb
ENV POSTGRES_USER=postgres
ENV POSTGRES_PASSWORD=postgres
ENV PGDATA=/pgdata
COPY --chown=postgres:postgres --from=donor /pgdata /pgdata

A tutorial can be found here:
https://medium.com/fintech-studios-engineering/creating-fast-lightweight-testing-databases-in-docker-2a8164d2f519 or here: #319 (comment)

This is no longer possible because the important part of the script is not triggered anymore. And there is no other args which exits immediately afterwards anymore.

Any hints how to avoid that?

nathanweeks added a commit to legumeinfo/lis_gis that referenced this issue Jul 9, 2020
mdillion/postgis image was discontinued...

docker-entrypoint.sh --help can no longer be used to prepopulate data
docker-library/postgres#636

Use healthcheck to determine if postgres is ready
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants