swiss_knight
swiss_knight

Reputation: 7821

pgadmin4 docker unable to dump servers config; No module named 'flask'

I'm trying to use the dpage/pgadmin4:latest docker image located here: https://hub.docker.com/r/dpage/pgadmin4/

But I struggle when I try to dump my servers setups setup from inside the docker container.

Here is a reproducible code:

docker-compose.yml:

version: '3.8'
services:
  pgadmin4:
    image: dpage/pgadmin4
    container_name: pgadmin4
    environment:
      - PGADMIN_DEFAULT_EMAIL=postgres@localhost
      - PGADMIN_DEFAULT_PASSWORD="K%)*r7K~57Kcnw"
      - PGADMIN_LISTEN_PORT=8080
    ports:
      - "8080:8080"
    restart: unless-stopped
    network_mode: host
docker-compose pull && docker-compose up --build -d

Then setup some server connections from the web interface at http://localhost:8080 and try to dump them from inside the container:

$ docker-compose exec pgadmin4 sh

Then:

/pgadmin4 $ python3 /pgadmin4/setup.py --dump-servers /tmp/servers.json
Traceback (most recent call last):
  File "/pgadmin4/setup.py", line 31, in <module>
    from pgadmin import create_app
  File "/pgadmin4/pgadmin/__init__.py", line 21, in <module>
    from flask import Flask, abort, request, current_app, session, url_for
ModuleNotFoundError: No module named 'flask'

I obviously tried to actually install flask itself (I thought it was!) but I also have some troubles here:

/pgadmin4 $ pip install flask
WARNING: The directory '/home/pgadmin/.cache/pip' or its parent directory is
not owned or is not writable by the current user. The cache has been disabled.
Check the permissions and owner of that directory. If executing pip with sudo,
you may want sudo's -H flag.

Defaulting to user installation because normal site-packages is not writeable

Collecting flask
  Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
     |████████████████████████████████| 94 kB 312 kB/s 
Collecting Jinja2>=2.10.1
  Downloading Jinja2-2.11.3-py2.py3-none-any.whl (125 kB)
     |████████████████████████████████| 125 kB 385 kB/s 
Collecting Werkzeug>=0.15
  Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
     |████████████████████████████████| 298 kB 279 kB/s 
Collecting itsdangerous>=0.24
  Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting click>=5.1
  Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
     |████████████████████████████████| 82 kB 332 kB/s 
Collecting MarkupSafe>=0.23
  Downloading MarkupSafe-1.1.1.tar.gz (19 kB)
Using legacy 'setup.py install' for MarkupSafe, since package 'wheel' is not installed.
Installing collected packages: MarkupSafe, Werkzeug, Jinja2, itsdangerous, click, flask
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/home/pgadmin'
Check the permissions.


Upvotes: 2

Views: 953

Answers (1)

Espi
Espi

Reputation: 71

It seems that the python3 installation that the container is using is not the same one in the path of sh

The one that it is using is at /venv/bin/python3 you can see it in the Dockerfile.

So if you run:

/venv/bin/python3 /pgadmin4/setup.py --dump-servers /tmp/servers.json

If you use that python binary the command will work. For me it was failing as the pgadmin user wouldn't have write permissions (folder owned by root) so I needed to login again using the root user. To do so you need to run:

docker-compose exec -it -u 0 pgadmin4 sh

Upvotes: 5

Related Questions