28

I have got the same problem described in this post, but inside a docker container. I don't really know where my pgadmin file reside to edit it's default path.How do I go about fixing this issue? Please be as detailed as possible because I don't know how to docker.

Here is an abstract of the verbatim of docker-compose up command:

php-worker_1  | 2020-11-11 05:50:13,700 INFO spawned: 'laravel-worker_03' with pid 67
pgadmin_1     | [2020-11-11 05:50:13 +0000] [223] [INFO] Worker exiting (pid: 223)
pgadmin_1     | WARNING: Failed to set ACL on the directory containing the configuration database:
pgadmin_1     |            [Errno 1] Operation not permitted: '/var/lib/pgadmin'
pgadmin_1     | HINT   : You may need to manually set the permissions on
pgadmin_1     |          /var/lib/pgadmin to allow pgadmin to write to it.
pgadmin_1     | ERROR  : Failed to create the directory /var/lib/pgadmin/sessions:
pgadmin_1     |            [Errno 13] Permission denied: '/var/lib/pgadmin/sessions'
pgadmin_1     | HINT   : Create the directory /var/lib/pgadmin/sessions, ensure it is writeable by
pgadmin_1     |          'pgadmin', and try again, or, create a config_local.py file
pgadmin_1     |          and override the SESSION_DB_PATH setting per
pgadmin_1     |          https://www.pgadmin.org/docs/pgadmin4/4.27/config_py.html
pgadmin_1     | /usr/local/lib/python3.8/os.py:1023: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
pgadmin_1     |   return io.open(fd, *args, **kwargs)
pgadmin_1     | [2020-11-11 05:50:13 +0000] [224] [INFO] Booting worker with pid: 224

my docker-compose.yml:

  ### pgAdmin ##############################################
  pgadmin:
    image: dpage/pgadmin4:latest
    environment:
      - "PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}"
      - "PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}"
    ports:
      - "${PGADMIN_PORT}:80"
    volumes:
      - ${DATA_PATH_HOST}/pgadmin:/var/lib/pgadmin
    depends_on:
      - postgres
    networks:
      - frontend
      - backend
4
  • 1
    Do you mount local host data folder inside container? Did you done with this step? pgadmin.org/docs/pgadmin4/latest/…
    – rzlvmp
    Commented Nov 11, 2020 at 6:03
  • @rzlvmp How can I confirm this? Sorry, I don't know docker.. Commented Nov 11, 2020 at 6:04
  • how do you run docker container? via command line? can you provide command? Ah, okay. You are using docker-compose. Please, provide docker-compose.yml description (don't forget to remove sensitive information).
    – rzlvmp
    Commented Nov 11, 2020 at 6:06
  • @rzlvmp sensitive data I believe is set unto environmental variables by a script i had to run before this step Commented Nov 11, 2020 at 6:11

4 Answers 4

42

Okay. looks like problem appears when you try to run pgadmin service.

This part

  ### pgAdmin ##############################################
  pgadmin:
    image: dpage/pgadmin4:latest
    environment:
      - "PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}"
      - "PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}"
    ports:
      - "${PGADMIN_PORT}:80"
    volumes:
      - ${DATA_PATH_HOST}/pgadmin:/var/lib/pgadmin
    depends_on:
      - postgres
    networks:
      - frontend
      - backend

As you can see you trying to mount local directory ${DATA_PATH_HOST}/pgadmin into container's /var/lib/pgadmin

    volumes:
      - ${DATA_PATH_HOST}/pgadmin:/var/lib/pgadmin

As you can read in this article your local ${DATA_PATH_HOST}/pgadmin directory's UID and GID must be 5050. Is this 5050?

You can check it by running

ls -l ${DATA_PATH_HOST}

Output will be like

drwxrwxr-x 1 5050 5050 12693 Nov 11 14:56 pgadmin

or

drwxrwxr-x 1 SOME_USER SOME_GROUP 12693 Nov 11 14:56 pgadmin

if SOME_USER's and SOME_GROUP's IDs are 5050, it is okay. 5050 as is also okay. If not, try to do as described in article above.

sudo chown -R 5050:5050 ${DATA_PATH_HOST}/pgadmin

Also you need to check is environment variable exists:

# run it as same user as you running docker-compose
echo ${DATA_PATH_HOST}

If output will be empty you need to set ${DATA_PATH_HOST} or allow docker to read variables from file. There are many ways to do it.

10
  • Apparetly I don't have my ${DATA_PATH_HOST} set as an environmental variable. ls -l is pointing at my current directory. Should I set this variable to some path? Commented Nov 11, 2020 at 6:27
  • what output will be if you run ls -l /pgadmin. What user you using when running docker-compose? root?
    – rzlvmp
    Commented Nov 11, 2020 at 6:31
  • I'm running as a normal user, (added myself to the docker group by following all the instructions in docs.docker.com/engine/install/ubuntu and docker compose docs. ls -l /pgadmin gives me no such files. did you mean the current directory? it has no pgadmin, although /var/lib got one. Commented Nov 11, 2020 at 6:42
  • I also followed your instructions on chown to var/lib/pgadmin, the error still persists. ls -l /var/lib: drwxrwxrwx 2 5050 5050 4096 Nov 11 15:37 pgadmin Commented Nov 11, 2020 at 6:46
  • 1
    if ${DATA_PATH_HOST} not set, ${DATA_PATH_HOST}/pgadmin == /pgadmin. Docker trying to create new directory if it not exists. Maybe docker reading env variables from another place. It depends on how you run docker-compose. Maybe /var/lib/pgadmin is a right one. There is two possible problems as I can see: 1. directory not created because ${DATA_PATH_HOST} not set, 2. directory exists but permissions are wrong (that must be 5050 or same as container user id).
    – rzlvmp
    Commented Nov 11, 2020 at 6:52
10

When running in kubernetes environment, I had to add these values.

   spec:
     containers:
       - name: pgadmin
         image: dpage/pgadmin4:5.4
         securityContext:
           runAsUser: 0
           runAsGroup: 0
1
  • This worked for me, this is what I thought of doing when I was running into issues
    – mrpbennett
    Commented Jul 19 at 15:30
7

If you're on Windows, add this line to your docker-compose.yml. It gives container an access to your local folder

version: "3.9"
services:
  postgres:
    user: root  <- this one 
    container_name: postgres_container
    image: postgres:14.2 
1
  • It doesn't work
    – West Side
    Commented Jun 2 at 16:10
6

adding user: '$UID:$GID' solved the problem for me.

version: '3.6'

services:
  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin4_container
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: 123123123
    user: '$UID:$GID'
    ports:
      - '8888:80'
    volumes:
      - ./docker-data/pgadmin-data:/var/lib/pgadmin
1
  • This is Does not work
    – West Side
    Commented Jun 2 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.