postgresql 使用dpage/pgadmin 4镜像运行docker-compose时出现权限异常

p1iqtdky  于 2023-10-18  发布在  PostgreSQL
关注(0)|答案(4)|浏览(162)

我试图用pgadmin 4构建一个ruby rails docker-compose postgreSQL数据库,但不断从容器获得权限异常。即使容器中的/bin/sh也会返回相同的错误。
Ubuntu 18.04.3 LTS
完整日志

db_1            | 
db_1            | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1            | 
db_1            | LOG:  database system was shut down at 2020-02-05 07:15:13 UTC
db_1            | LOG:  MultiXact member wraparound protections are now enabled
db_1            | LOG:  autovacuum launcher started
db_1            | LOG:  database system is ready to accept connections
pgadmin_1       | [2020-02-05 07:15:17 +0000] [1] [INFO] Starting gunicorn 19.9.0
pgadmin_1       | [2020-02-05 07:15:17 +0000] [1] [INFO] Listening at: http://[::]:80 (1)
pgadmin_1       | [2020-02-05 07:15:17 +0000] [1] [INFO] Using worker: threads
pgadmin_1       | [2020-02-05 07:15:17 +0000] [13] [INFO] Booting worker with pid: 13
pgadmin_1       | [2020-02-05 07:15:17 +0000] [13] [ERROR] Exception in worker process
pgadmin_1       | Traceback (most recent call last):
pgadmin_1       |   File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
pgadmin_1       |     worker.init_process()
pgadmin_1       |   File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 104, in init_process
pgadmin_1       |     super(ThreadWorker, self).init_process()
pgadmin_1       |   File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
pgadmin_1       |     self.load_wsgi()
pgadmin_1       |   File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
pgadmin_1       |     self.wsgi = self.app.wsgi()
pgadmin_1       |   File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
pgadmin_1       |     self.callable = self.load()
pgadmin_1       |   File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
pgadmin_1       |     return self.load_wsgiapp()
pgadmin_1       |   File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
pgadmin_1       |     return util.import_app(self.app_uri)
pgadmin_1       |   File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
pgadmin_1       |     __import__(module)
pgadmin_1       |   File "/pgadmin4/run_pgadmin.py", line 4, in <module>
pgadmin_1       |     from pgAdmin4 import app
pgadmin_1       |   File "/pgadmin4/pgAdmin4.py", line 109, in <module>
pgadmin_1       |     app = create_app()
pgadmin_1       |   File "/pgadmin4/pgadmin/__init__.py", line 350, in create_app
pgadmin_1       |     paths.init_app(app)
pgadmin_1       |   File "/pgadmin4/pgadmin/utils/paths.py", line 92, in init_app
pgadmin_1       |     'The user does not have permission to read and write to the '
pgadmin_1       | Exception: The user does not have permission to read and write to the specified storage directory.
pgadmin_1       | [2020-02-05 07:15:17 +0000] [13] [INFO] Worker exiting (pid: 13)
pgadmin_1       | [2020-02-05 07:15:17 +0000] [1] [INFO] Shutting down: Master
pgadmin_1       | [2020-02-05 07:15:17 +0000] [1] [INFO] Reason: Worker failed to boot.
***_pgadmin_1 exited with code 3

docker-compose.yml文件

version: '3'
services:
  db:
    image: postgres:9.5
    volumes:
      - postgres:/var/lib/postgresql/data
  pgadmin:
    image: dpage/pgadmin4
    volumes:
      - pgadmin:/var/lib/pgadmin/storage
    ports:
      - '3030:80'
    environment:
      PGADMIN_DEFAULT_EMAIL: 'admin'
      PGADMIN_DEFAULT_PASSWORD: password
    depends_on:
      - db
volumes:
  postgres:
  pgadmin:

(ruby铁路服务被删除,因为我不认为这是相关的)
在pgadmin容器中重新移动卷允许我在容器中使用/bin/sh,但我不能使用任何命令

v09wglhw

v09wglhw1#

我也有同样的问题。我可以通过将卷安装在稍微不同的位置来解决这个问题:

volumes:
      - pgadmin:/var/lib/pgadmin4/storage

请注意,在您的脚本中,它被挂载在/var/lib/pgadmin/storage

fdbelqdn

fdbelqdn2#

我遇到了同样的问题与图像dpage/pgadmin 4:4.18。挖了一点,不管出于什么原因,pgadmin没有在服务器模式下运行,这导致它使用不同的目录,失败的权限检查。
为了解决这个问题,我添加了一个PGADMIN_CONFIG_SERVER_MODE环境变量,并将其设置为True。在本例中,您将向docker-compose.yml添加另一个环境变量,内容如下:

PGADMIN_CONFIG_SERVER_MODE: True

第一个字母大写是非常重要的。这一行被转换成Python代码(在config_distro.py中的SERVER_MODE = True,如果T没有大写,它将失败。

b0zn9rqh

b0zn9rqh3#

我也有类似的问题。从你发布的日志来看。如果您阅读日志的最后几行,您会注意到该问题与权限有关:“例外:用户没有对指定存储目录进行读写的权限。”
dpage/pgadmin 4容器中的用户没有在指定目录(在本例中为Map到映像卷的pgadmin文件夹)中进行读写的权限。
默认情况下,pgadmin映像的用户名为 pgadmin user(UID:5050)(GID:5050) 并且用户不能在主机(您的机器)中读写。要做到这一点,你只需要运行以下命令:

`sudo chown -R 5050:5050 <host_directory>`

运行docker compose,然后导航到它创建的文件夹,确保你在里面,Map到卷的文件夹,你的案例:pgAdmin
一旦进入文件夹,从终端,执行如下操作:sudo chown -R 5050:5050 .现在用户有读和写的权限。你再次运行docker compose,它会创建所有需要的文件夹和文件,容器应该可以正常运行。
在这里检查文档

xpszyzbs

xpszyzbs4#

尝试删除并重新创建Docker卷,
docker volume ls
以查找卷名,后跟
docker volume rm <volume name>
这将重新创建可能导致问题的卷

相关问题