Cant login with docker compose to Postgres via pgadmin - postgresql

I have the following docker-compose:
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: postgres
volumes:
- postgres:/pgdata
ports:
- "5432:5432"
pdadmin:
image: dpage/pgadmin4
restart: always
ports:
- "8080:80"
environment:
PGADMIN_DEFAULT_EMAIL: example#gmail.com
PGADMIN_DEFAULT_PASSWORD: example
volumes:
postgres:
when I try to login to postgres via pgadmin i am getting the error: password authentication failed for user "postgres"
I am trying with user postgres and password postgres.
I also tryied to add explisit POSTGRES_USER to the env with no success.
How can I login to my postgres database?
Thanks

you're very close:
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_USER: postgres # <-- add this
POSTGRES_PASSWORD: postgres
volumes:
- postgres:/pgdata
ports:
- "5432:5432"
pdadmin:
image: dpage/pgadmin4
restart: always
ports:
- "8080:80"
environment:
PGADMIN_DEFAULT_EMAIL: example#gmail.com
PGADMIN_DEFAULT_PASSWORD: example
depends_on: # <-- add this
- db # <-- add this
links: # <-- add this
- db # <-- add this
volumes:
postgres:
Then connect to pgadmin http://localhost:8080
when you want to add new server you need to add the IP of the container
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_id>
That it !

try it
PGADMIN_DEFAULT_PASSWORD: Example123
Use a mixture of upper and lower case letters and numerics

Related

I don't manage to configure volumes in docker-compose to have a folder reachable by dockerized pgAdmin, to restore a database

I have setup from a tutorial a pgadmin4 container and a PostgreSQL container with the following docker-compose:
version: "2"
services:
db:
image: postgres:14
restart: always
environment:
POSTGRES_DB: postgres
POSTGRES_USER: admin
POSTGRES_PASSWORD: secret
PGDATA: /var/lib/postgresql/data
volumes:
- db-data:/opt/docker/pgadmin4/postgresql/data
- /home/laurent/Documents/Informatique/Docker/sample-database:/opt
ports:
- "5432:5432"
pgadmin:
image: dpage/pgadmin4:4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin#linuxhint.com
PGADMIN_DEFAULT_PASSWORD: secret
PGADMIN_LISTEN_PORT: 80
ports:
- "8080:80"
volumes:
- pgadmin-data:/var/lib/pgadmin
- /home/laurent/Documents/Informatique/Docker/sample-database:/opt
links:
- "db:pgsql-server"
volumes:
db-data:
pgadmin-data:
In both conainers, I have mounted the path /home/laurent/Documents/Informatique/Docker/sample-database where I have put a sample database.
After having created the dvdrental database as explained in the tutorial, I try to import it with restore, but I cannot find my /opt/dvdrental.tar as expected.
When I Select file, I get this:
If I add opt in the path and refresh, nothing more.
But if I open a console in both containers, I have /opt/dvdrental.tar.
What do I miss?

docker-compose.yml for Postgres works either way, but not the expected one

I have the following docker-compose.yml for running Postgres with Docker:
version: '3.8'
services:
postgres:
image: postgres:14.2-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_DB: mydatabasename
PGDATA: /data/mydatabasename
volumes:
- postgres:/data/postgres
ports:
- '5432:5432'
networks:
- postgres
restart: unless-stopped
pgadmin:
... placeholder
networks:
postgres:
driver: bridge
volumes:
postgres:
pgadmin:
It works. What I don't understand, is that these two combinations work:
PGDATA: /data/mydatabasename
volumes:
- postgres:/data/postgres
and
PGDATA: /data/postgres
volumes:
- postgres:/data/mydatabasename
But this does not work:
PGDATA: /data/mydatabasename
volumes:
- postgres:/data/mydatabasename
I would just get: error: database "mydatabasename" does not exist.
The latter was my first attempt connecting everything though. So I am wondering, why do both fields not map to the actual database name? Thanks for your help!
Docker Compose File
version: '3'
services:
postgres:
image: postgres:alpine
container_name: postgres
restart: always
posts:
- 5432:5432
volumes:
- ./data_backup:/var/lib/postgresql/data #mount the data locally
env_file:
- .env
networks:
- postgres-net
pgadmin:
image: dpage/pgadmin4:6
restart: always
ports:
- 8080:80
volumes:
- pgadmin:/var/lib/pgadmin
env_file:
- .env
depends_on:
- postgres
netwroks:
- postgres-net
networks:
postgres-net:
name: postgres-net
.env File
#postgres
POSTGRES_PASSWORD="secure_password"
POSTGRES_DB=your_db_name
POSTGRES_USER=db_user_name
#pgadmin
PGADMIN_DEFAULT_EMAIL=ariful#firora.com
PGADMIN_DEFAULT_PASSWORD="secure_password"
PGADMIN_LISTEN_PORT=80
Since you may try to bind the database folder which was never created. Alternatively you can bind /var/lib/postgresql/data this path to store whatever database you created or about create in future.

pgAdmin disable login dialog / automatic login

I'm running pgAdmin using docker-compose with the following script:
version: "3.9"
services:
postgres:
image: "postgres:13"
container_name: "postgres"
environment:
POSTGRES_PASSWORD: pwd
ports:
- "5432:5432"
volumes:
- ./initdb:/docker-entrypoint-initdb.d
pgadmin:
image: "dpage/pgadmin4"
container_name: "pgadmin"
environment:
PGADMIN_DEFAULT_EMAIL: pgadmin#mycomp.com
PGADMIN_DEFAULT_PASSWORD: secret
links:
- postgres:postgres
ports:
- 5050:80
The script uses PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD to change the default pgAdmin credentials.
However, as I'm running this docker instance on a development machine, I would like to auto-login into pgAdmin.
Is it possible to disable the login / automatically login?
You have to set SERVER_MODE parameter to False on your development machine. Due to documentation you should use PGADMIN_CONFIG_SERVER_MODE in your docker-compose.yml:
version: "3.9"
services:
postgres:
image: "postgres:13"
container_name: "postgres"
environment:
POSTGRES_PASSWORD: pwd
ports:
- "5432:5432"
volumes:
- ./initdb:/docker-entrypoint-initdb.d
pgadmin:
image: "dpage/pgadmin4"
container_name: "pgadmin"
environment:
PGADMIN_DEFAULT_EMAIL: pgadmin#mycomp.com
PGADMIN_DEFAULT_PASSWORD: secret
PGADMIN_CONFIG_SERVER_MODE: 'False'
links:
- postgres:postgres
ports:
- 5050:80
Now if you have a problem with the missing crypt key, you can disable MASTER_PASSWORD by specifying this parameter:
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False'

docker pgadmin connect to Postgres failing

I'm trying to run pgadmin and postgres on docker. both services seems to work. However to able to connect to postgres through pgadmin. return password incorrect even after typing the password you see in the docker-compose file.
docker-compose
services:
postgres:
container_name: postgres
image: postgres
environment:
POSTGRES_USER: danny329
POSTGRES_PASSWORD: danny329
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- "5432:5432"
networks:
- postgres
restart: unless-stopped
pgadmin:
container_name: pgadmin_container
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4#pgadmin.org}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
PGADMIN_CONFIG_SERVER_MODE: 'False'
volumes:
- pgadmin:/var/lib/pgadmin
ports:
- "5050:80"
networks:
- postgres
restart: unless-stopped
networks:
postgres:
driver: bridge
volumes:
postgres:
pgadmin:
Error screenshot:
Note: the password i used is 'danny329'
Since both your postgres container and pgadmin container are running on the same Docker bridge network, you can connect them to each other using thier container name. For more info see Networking in Compose
In this case for the pgadmin you can set the hostname to be postgres:

I cannot connect from adminer to postgresql

I try to up postgresql and adminer via docker container. But from adminer I cannot enter to postgresql with password and user I whote.
SQLSTATE[08006] [7] FATAL: password authentication failed for user "root"
I tried all.
version: '3'
services:
web:
build: .
environment:
- APACHE_RUN_USER=www-data
volumes:
- ./blog:/var/www/html/
ports:
- 8080:80
working_dir: /var/www/html/
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: kisphp
POSTGRES_USER: root
POSTGRES_DB: kisphp
ports:
- "5432:5432"
volumes:
- ./postgres:/var/lib/postgresql/data
adminer:
image: adminer
restart: always
ports:
- "6080:8080"
This docker-compose configuration works well.
Try recreating it from scratch:
Delete ./postgres folder
docker-compose stop
docker-compose down
docker-compose up -d