19

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
Silver Flash
  • 871
  • 3
  • 7
  • 16
  • 1
    Do you mount local host data folder inside container? Did you done with this step? https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html#mapped-files-and-directories – rzlvmp Nov 11 '20 at 06:03
  • @rzlvmp How can I confirm this? Sorry, I don't know docker.. – Silver Flash Nov 11 '20 at 06: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 Nov 11 '20 at 06:06
  • @rzlvmp sensitive data I believe is set unto environmental variables by a script i had to run before this step – Silver Flash Nov 11 '20 at 06:11

3 Answers3

32

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.

rzlvmp
  • 7,512
  • 5
  • 16
  • 45
  • 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? – Silver Flash Nov 11 '20 at 06:27
  • what output will be if you run `ls -l /pgadmin`. What user you using when running docker-compose? root? – rzlvmp Nov 11 '20 at 06:31
  • I'm running as a normal user, (added myself to the docker group by following all the instructions in https://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. – Silver Flash Nov 11 '20 at 06: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` – Silver Flash Nov 11 '20 at 06: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 Nov 11 '20 at 06:52
  • `drwxrwxrwx` means that all users can read/write into directory. I guess it is not correctly mounted inside container. check `${DATA_PATH_HOST}` – rzlvmp Nov 11 '20 at 06:58
  • your previous comment gave me the hint. I exported `${DATA_PATH_HOST} to /var/lib` and reran docker-composer and it worked!! Thank you, this solved my issue. – Silver Flash Nov 11 '20 at 07:07
  • ok. added this information in answer to complete it. Don't forget to set another variables too. – rzlvmp Nov 11 '20 at 07:25
  • What sort of stupid containerization is this of pgadmin where you need to get inside container to assign permission? – Simple Fellow Jan 18 '22 at 06:50
  • @SimpleFellow You don't need. But here is mounted external volume with own permissions. Docker don't know anything about what happens inside external `${DATA_PATH_HOST}/pgadmin`. – rzlvmp Jan 18 '22 at 08:23
5

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
bhargav joshi
  • 329
  • 3
  • 6
4

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 
osynavets
  • 1,199
  • 1
  • 12
  • 22