-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Version postgres:9.4 doesn't create role/password #41
Comments
That is a bit strange, I'm not having any problems here and I just did a |
I'm still having the problem. Just to clarify, the expected behavior is that setting those variables will create the role and password and restrict login to those credentials. When I pass the variables and then try to login to the container, Postgres says the role doesn't exist. Edit: It's hard to put a minimal case because a client like In case this helps,
and
|
Yes it creates the user specified as a superuser with the password and creates a database for them. Here is how I'm testing it: $ docker run -it --rm --name pg1 -e POSTGRES_PASSWORD=12345 -e POSTGRES_USER=bob postgres:9.4
$ docker run -it --link pg1:postgres --rm postgres:9.4 sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U bob' |
I just did that and get Edit: I tried on another machine and it does work. Clearly something local here -- sorry. Feel free to close this. |
I get the same issue
Not sure how the logic of changing role/password could be version dependent. But happy to help to try and debug why some of us get this issue. I've tried setting POSTGRES_USER/POSTGRES_PASSWORD on a container with an existing db volume, and with a blank data volume in case the user/password is only set up the first time things get initialised (the documentation is unclear if setting user/password will be respected on a container with an existing data volume). |
Tracked this down to the docker-entrypoint.sh in my pulled image being different to the one in this repo: #!/bin/bash
set -e
if [ "$1" = 'postgres' ]; then
chown -R postgres "$PGDATA"
if [ -z "$(ls -A "$PGDATA")" ]; then
gosu postgres initdb
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
{ echo; echo 'host all all 0.0.0.0/0 trust'; } >> "$PGDATA"/pg_hba.conf
if [ -d /docker-entrypoint-initdb.d ]; then
for f in /docker-entrypoint-initdb.d/*.sh; do
[ -f "$f" ] && . "$f"
done
fi
fi
exec gosu postgres "$@"
fi
exec "$@" And turns out I was using the version tagged 9.3 in my config. |
I had this issue, then realised I had another postgres working on my machine. Oops. Make sure you check that! |
I'm having the same issue. @liamdawson: for you the problem was that postgres was running on your machine or installed? How did you solve this issue? |
@Alexis-benoist I had postgres actually running on my host, so it took precedence over the version run in Docker. |
This is how you start the docker postgres image and access: $ docker run -it --rm --name pg1 -p 5432:5432 -e POSTGRES_PASSWORD=12345 -e POSTGRES_USER=bob postgres:9.4
$ psql -h dockerhost -U bob
The incoming ports was not defined in @yosifkit's example. :-) |
I've got the same issue using docker-compose |
@tibo, with docker-compose, it tries to preserve volumes between runs; since the user is only created on a new database, you probably need to |
@yosifkit good call. setting POSTGRES_USER at the creation of the container works. |
I have the same problem with docker-compose and an specified POSTGRES_USER:
Results in
It works with the 9.5 tag. |
I have this problem with 9.5 tag. I am running it from OS X (docker-machine with virtual box drivers). The same files do no have issues running from a ubuntu 14.04 machine. |
@servomac or @jmerkow, are you using docker-compose as well? Any environment variable to setup the user, password, and database are only done on the first initialization of the database. If you already ran it once and are just restarting to apply new variables then compose will start a new container that reuses the already initialized volume. See my comment above. |
@yosifkit I also ran into this problem. But the thing is that I tried deleting and recreating the volumes/container/images and starting from scratch, but still I can't get it to create the user with compose. Before it has been working fine and I haven't touched my docker-compose.yml or Dockerfiles. A quick manual fix though: |
I figured out the problem, by reading the logs... I had set the PG* env variables to make psql login automatically and of course that broke the init script that uses psql. That's why the problem occurred now when I reinitialized the image. |
Also another issue might be that you have hanging volumes. I had this same issue and I couldn't figure out why. I then figured out it had something to do with volumes and the problem was resolved after I ran this command: |
I have the same issue using docker-compose. I tried in 2 different machines (MacOS + parallels docker machine and Fedora24). If I create the postgres container manually it works. |
Related comment: #203 (comment). |
@yosifkit now to delete volumes: |
Watch this video on youTube, |
I encountered the issue due to a mismatch between the I had to edit the init script that I was writing to include the #!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" -d "$POSTGRES_DB" <<-EOSQL
CREATE USER docker;
CREATE DATABASE docker;
GRANT ALL PRIVILEGES ON DATABASE docker TO docker;
EOSQL |
To close the loop I also provided @yosifkit 's 'delete the volume' approach as an answer on Stackoverflow (although at the time I answered I didn't know about this issue). |
I'm still experiencing this issue on Supposedly the |
@mwthink, that would be because any connection via localhost is trusted without a password (as long as the username matches): # pg_hba.conf (when setting pass via env vars)
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host all all all md5 Here is the code that is used to setup the initial user and Lines 66 to 120 in 61e369c
|
Encountering this issue with the image tagged I have tried on two separate Ubuntu servers:
I build the container like so (I've also tried with docker-compose.yml):
After the initial run command (with no pre-existing bind directories or even images), I can get into bash for the container, and echo the
I know that there is nothing wrong with the remote connection, as I can see movement in the logs every time I connect, and it tells me when the user doesn't exist in the server's logs as well as on client machine. This appears to purely be an issue with how the database is being initialized, especially since the container has those environment variables set. I'm not sure what else to dive into, as the entry-point.sh appears to be grabbing the variables on lines 65-87, but I am available for some troubleshooting if there are any suggestions. postgres/10/docker-entrypoint.sh Lines 65 to 87 in 61e369c
|
@sk33z3r, your setup looks correct. The $ docker run -it --rm --net $network -e PGPASSWORD=$dbusrpwd postgres psql --host $sqlnm --username $dbusr Is |
@yosifkit I knew this would happen! I apologize for cluttering this issue up... I was misreading the logs. I'm getting an error that the database with the name of I was doing (from the client machine) Now that I've educated myself more, running this command is working: I've worked primarily with MySQL, and so was not entirely familiar with the |
@sk33z3r, no problem! As the original issue also seems to be solved, I'll close the issue. |
if anyone still ends up here looking for the solution: envs need to be ordered POSTGRES_DB > POSTGRES_USER > POSTGRES_PASSWORD. |
same issue. Here is the db_1_9392cbf8fcab | waiting for server to start....LOG: database system was shut down at 2018-11-26 04:11:56 UTC
db_1_9392cbf8fcab | LOG: MultiXact member wraparound protections are now enabled
db_1_9392cbf8fcab | LOG: database system is ready to accept connections
db_1_9392cbf8fcab | LOG: autovacuum launcher started
db_1_9392cbf8fcab | done
db_1_9392cbf8fcab | server started
db_1_9392cbf8fcab | CREATE DATABASE
db_1_9392cbf8fcab |
db_1_9392cbf8fcab |
db_1_9392cbf8fcab | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1_9392cbf8fcab |
db_1_9392cbf8fcab | LOG: received fast shutdown request
db_1_9392cbf8fcab | LOG: aborting any active transactions
db_1_9392cbf8fcab | waiting for server to shut down....LOG: autovacuum launcher shutting down
db_1_9392cbf8fcab | LOG: shutting down
db_1_9392cbf8fcab | LOG: database system is shut down
db_1_9392cbf8fcab | done
db_1_9392cbf8fcab | server stopped As you can see, there is no image: update: Finally, I found the reason why I always get
And, then I got
The postgres process which
Then, everything works fine. |
If someone is having this problem please do check if you are defining postgres service in the docker-compose file again in the end. |
i am experiencing the same issue on kubernetes when i created postgres pods on kubernetes, envs are set correctly. but when i exec psql command. It showed Anyone know how to fix this issue? |
@lhb008, the |
ensure that sudo docker run --rm --name pg-docker \
-e POSTGRES_PASSWORD=password \
-p 5432:5432 \
-v $HOME/docker/volumes/postgres:/var/lib/postgresql/data \
-d postgres:latest To create server connection use To accessing data you should use PGAdmin - linked to sudo docker run -p 8085:80 \
--link pg-docker:pg-docker \
-e "PGADMIN_DEFAULT_EMAIL=admin@local.com" \
-e "PGADMIN_DEFAULT_PASSWORD=password" \
-d dpage/pgadmin4 To access database run |
Best answer...! |
Can someone post their docker-compose.yml file? I've tried using the correct order and I've even read through the docker compose logs and I never see a create statement. |
@dgreene1: See the docs from Docker Hub; https://github.com/docker-library/docs/tree/3130985bd950650b4cd31cb1ef973d30f9f0c154/postgres#-via-docker-stack-deploy-or-docker-compose (the play-with-docker link will even let you explore that compose file on a fresh setup). |
This worked for me, but why is this a solution? |
It can''t; order of environment variable definitions in the Locking since the original issue was solved. |
Setting POSTGRES_USER and POSTGRES_PASSWORD on the 9.4 tag doesn't create the role and password for me. (Previous versions work.)
The text was updated successfully, but these errors were encountered: