Markus Weber
Markus Weber

Reputation: 1107

Docker dpage/pgadmin4 error: specified user does not exist

This is the docker-compose.yml file:

version: '3'

services:
############################
# Setup database container #
############################
  postgres_db:
    image: postgres
    restart: always
    ports:
      - ${POSTGRES_PORT}:${POSTGRES_PORT}
    environment: 
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - PGDATA=/var/lib/postgresql/data/pgdata
      - POSTGRES_DB=${POSTGRES_DB}
    volumes:
      - ./data:/var/lib/postgresql/data 
    networks:
      - db_network

  pgadmin:
    image: dpage/pgadmin4:4.19
    restart: always
    ports:
      - 8001:8080/tcp
    environment: 
      - PGADMIN_LISTEN_ADDRESS=0.0.0.0
      - PGADMIN_LISTEN_PORT=8080
      - PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
      - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
    networks:
      - db_network

networks: 
  db_network:
    driver: bridge

There is a .env file in the same directory.

# The above refers to the name of the postgres container since using docker-compose
# This is because docker-compose creates a user-defined network. Kubernetes also does this.
POSTGRES_PORT=5432
POSTGRES_USER=website
POSTGRES_PASSWORD=website
POSTGRES_DB=wikifakes_main
[email protected]
PGADMIN_DEFAULT_PASSWORD=my-secure-password 

When executing docker-compose up --build both docker start and I can access the pgAdmin4 website via localhost:8001. However, after entering the credentials, I get the following response:

Specified user does not exist

Why does the specified user not exist and how should I change my environment so that I can log in?

The login on an pgadmin4 docker created via docker run --rm -e PGADMIN_DEFAULT_EMAIL="[email protected]" -e PGADMIN_DEFAULT_PASSWORD="my-secure-password" -p 8001:80 dpage/pgadmin4 works alright though.

Upvotes: 5

Views: 10511

Answers (3)

Delete /var/lib/pgadmin/pgadmin4.db (it might be mounted to somewhere) or try to delete it inside the container and run it again.

Your problem is most likely because you ever start the container, then you change PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD.

There is a code snippet when your container starts

if [ ! -f /var/lib/pgadmin/pgadmin4.db ]; then

When the container starts for the first time, it will create a file named /var/lib/pgadmin/pgadmin4.db. PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD will be stored inside pgadmin4.db (with the password being hashed).

So, when the container starts again, pgadmin4.db file has been created and will not go to the branch in the code snippet above so that PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD change will not be updated.


Alternately, you can exec shell to the container

[user:host ~]$ docker exec -it <your container> sh

and inspect the email registered

[pgadmin:<container_id> /pgadmin4]$ cat /var/lib/pgadmin/pgadmin4.db | egrep '\S+@\S+\.\S+'

Upvotes: 6

Youssef
Youssef

Reputation: 3114

tty is NOT required but you need to mention dependencies (depends_on and links) !

version: '3.1'

services:
############################
# Setup database container #
############################
  postgres_db:
    image: postgres
    restart: always
    ports:
      - ${POSTGRES_PORT}:${POSTGRES_PORT}
    environment: 
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - PGDATA=/var/lib/postgresql/data/pgdata
      - POSTGRES_DB=${POSTGRES_DB}
    volumes:
      - ./data:/var/lib/postgresql/data 
    networks:
      - db_network

  pgadmin:
    image: dpage/pgadmin4:4.19
    restart: always
    ports:
      - 8001:8080/tcp
    environment: 
      - PGADMIN_LISTEN_ADDRESS=0.0.0.0
      - PGADMIN_LISTEN_PORT=8080
      - PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
      - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
    networks:
      - db_network
    # ADD THIS LINE, TO BE ABLE TO LOGIN
    tty: true
    depends_on: # <-- !!!!!
      - postgres_db # <-- !!!!!
    links: # <-- !!!!!
      - postgres_db # <-- !!!!!

Upvotes: 0

Markus Weber
Markus Weber

Reputation: 1107

Add tty: true to the pgadmin service in the docker-compose.yml file.


  pgadmin:
    image: dpage/pgadmin4:4.19
    restart: always
    ports:
      - 8001:8080/tcp
    environment: 
      - PGADMIN_LISTEN_ADDRESS=0.0.0.0
      - PGADMIN_LISTEN_PORT=8080
      - PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
      - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
    networks:
      - db_network
    # ADD THIS LINE
    tty: true

So the complete file will look as follows:

version: '3'

services:
############################
# Setup database container #
############################
  postgres_db:
    image: postgres
    restart: always
    ports:
      - ${POSTGRES_PORT}:${POSTGRES_PORT}
    environment: 
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - PGDATA=/var/lib/postgresql/data/pgdata
      - POSTGRES_DB=${POSTGRES_DB}
    volumes:
      - ./data:/var/lib/postgresql/data 
    networks:
      - db_network

  pgadmin:
    image: dpage/pgadmin4:4.19
    restart: always
    ports:
      - 8001:8080/tcp
    environment: 
      - PGADMIN_LISTEN_ADDRESS=0.0.0.0
      - PGADMIN_LISTEN_PORT=8080
      - PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
      - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
    networks:
      - db_network
    # ADD THIS LINE, TO BE ABLE TO LOGIN
    tty: true

networks: 
  db_network:
    driver: bridge

Upvotes: 5

Related Questions