【问题标题】:PostgreSQL not working on docker when volume is initialized卷初始化时 PostgreSQL 无法在 docker 上工作
【发布时间】:2020-04-17 13:50:26
【问题描述】:

我正在使用 Windows 泊坞窗 我的 docker-compose 文件如下所示:

version: '3.5'

services:
  postgres:
    container_name: postgres_container
    image: postgres
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-root}
      PGDATA: /data/postgres
    volumes:
      -  ./postgres-data:/var/
    ports:
      - "5432:5432"
    restart: unless-stopped 

当我构建它时,我得到以下错误日志并且容器退出

Attaching to postgres_container
postgres_container | The files belonging to this database system will be owned by user "postgres".
postgres_container | This user must also own the server process.
postgres_container |
postgres_container | The database cluster will be initialized with locale "en_US.utf8".
postgres_container | The default database encoding has accordingly been set to "UTF8".
postgres_container | The default text search configuration will be set to "english".
postgres_container |
postgres_container | Data page checksums are disabled.
postgres_container |
postgres_container | fixing permissions on existing directory /data/postgres ... ok
postgres_container | creating subdirectories ... ok
postgres_container | selecting dynamic shared memory implementation ... posix
postgres_container | selecting default max_connections ... 100
postgres_container | selecting default shared_buffers ... 128MB
postgres_container | selecting default time zone ... Etc/UTC
postgres_container | creating configuration files ... ok
postgres_container | running bootstrap script ... ok
postgres_container | performing post-bootstrap initialization ... ok
postgres_container | syncing data to disk ... ok
postgres_container |
postgres_container |
postgres_container | Success. You can now start the database server using:
postgres_container |
postgres_container |     pg_ctl -D /data/postgres -l logfile start
postgres_container |
postgres_container | initdb: warning: enabling "trust" authentication for local connections
postgres_container | You can change this by editing pg_hba.conf or using the option -A, or
postgres_container | --auth-local and --auth-host, the next time you run initdb.
postgres_container | waiting for server to start....2020-04-17 13:18:31.599 UTC [47] LOG:  starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_container | 2020-04-17 13:18:31.607 UTC [47] LOG:  could not bind Unix address "/var/run/postgresql/.s.PGSQL.5432": Input/output error
postgres_container | 2020-04-17 13:18:31.607 UTC [47] HINT:  Is another postmaster already running on port 5432? If not, remove socket file "/var/run/postgresql/.s.PGSQL.5432" and retry.
postgres_container | 2020-04-17 13:18:31.607 UTC [47] WARNING:  could not create Unix-domain socket in directory "/var/run/postgresql"
postgres_container | 2020-04-17 13:18:31.607 UTC [47] FATAL:  could not create any Unix-domain sockets
postgres_container | 2020-04-17 13:18:31.610 UTC [47] LOG:  database system is shut down
postgres_container |  stopped waiting
postgres_container | pg_ctl: could not start server
postgres_container | Examine the log output.
postgres_container |
postgres_container | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_container |
postgres_container | 2020-04-17 13:18:32.246 UTC [1] LOG:  starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_container | 2020-04-17 13:18:32.246 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_container | 2020-04-17 13:18:32.246 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_container | 2020-04-17 13:18:32.255 UTC [1] LOG:  could not bind Unix address "/var/run/postgresql/.s.PGSQL.5432": Input/output error
postgres_container | 2020-04-17 13:18:32.255 UTC [1] HINT:  Is another postmaster already running on port 5432? If not, remove socket file "/var/run/postgresql/.s.PGSQL.5432" and retry.
postgres_container | 2020-04-17 13:18:32.255 UTC [1] WARNING:  could not create Unix-domain socket in directory "/var/run/postgresql"
postgres_container | 2020-04-17 13:18:32.255 UTC [1] FATAL:  could not create any Unix-domain sockets
postgres_container | 2020-04-17 13:18:32.259 UTC [1] LOG:  database system is shut down
postgres_container exited with code 1

我检查了 5432 端口是否打开,没有进程在使用它。

当我从 docker-compose.yml 文件中删除卷时,它可以工作 完美

我使用的卷 ./postgres-data 是我系统上的本地目录,我想将它映射到 PostgreSQL 容器以恢复数据库。

【问题讨论】:

  • 尝试将“./postgres-data:/var/lib/postgresql/data”作为卷
  • 您在所有/var 上使用绑定挂载隐藏了一堆系统目录;例如,标准的/var/run 目录在此设置中将不存在,这会导致您失败。
  • @TibebeselasieMehari 我试过它开始工作,但是卷没有被映射,即每当我将备份文件放在我的本地目录中时它在容器中不可用
  • @DavidMaze 感谢更改目录及其工作

标签: linux postgresql docker docker-compose dockerfile


【解决方案1】:

您在 Windows 上使用 docker 并将创建套接字的目录 (/var) 挂载为卷,但 Windows 文件系统不支持 unix 套接字。

更改配置以便:

  • 将 unix 套接字 (/var/run/postgresql/...) 留在 docker 内而不作为卷安装

  • 将数据目录挂载为卷

【讨论】:

    猜你喜欢
    • 2021-09-06
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-25
    • 2020-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多