postgresql - 无法使用Docker Compose与Wordpress建立postgres连接

标签 postgresql docker docker-compose

没有包括docker-compose在内的这类问题。

我找不到docker-compose.yml文件有什么问题。
顺便说一句,我不想​​在docker hub上使用现成的“wp-postgres”镜像。

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - wordpress:/var/www/html

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_DB_NAME: exampledb
      POSTGRES_PASSWORD: examplepass
      POSTGRES_DB_USER: exampleuser
    volumes:
      - db:/var/lib/postgres

volumes:
  wordpress:
  db:

这是日志:
dpress_1  | WordPress not found in /var/www/html - copying now...
wordpress_1  | Complete! WordPress has been successfully copied to /var/www/html
wordpress_1  | [02-Mar-2020 18:33:10 UTC] PHP Warning:  mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
wordpress_1  | MySQL Connection Error: (2002) Connection refused
wordpress_1  |
wordpress_1  | WARNING: unable to establish a database connection to 'db'
wordpress_1  |   continuing anyways (which might have unexpected results)
wordpress_1  |
wordpress_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.25.0.3. Set the 'ServerName' directive globally to suppress this message
wordpress_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.25.0.3. Set the 'ServerName' directive globally to suppress this message
wordpress_1  | [Mon Mar 02 18:33:38.074477 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.15 configured -- resuming normal operations
wordpress_1  | [Mon Mar 02 18:33:38.074510 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
db_1         |
db_1         | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1         |
db_1         | 2020-03-02 19:40:34.511 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
db_1         | 2020-03-02 19:40:34.512 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1         | 2020-03-02 19:40:34.512 UTC [1] LOG:  listening on IPv6 address "::", port 5432

最佳答案

您不能将PostgreSQL数据库与正式的Wordpress图像一起使用。您会在日志中看到:

wordpress_1  | [02-Mar-2020 18:33:10 UTC] PHP Warning:  mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
wordpress_1  | MySQL Connection Error: (2002) Connection refused

官方的Wordpress图像假定使用mysql数据库,但不幸的是没有提供任何其他可配置的更改。如果要使用Postgres,则需要使用wp-postgres图像,或使用此官方Wordpress图像的修改版本:

https://hub.docker.com/r/ntninja/wordpress-postgresql

披露:我为EnterpriseDB (EDB)工作

关于postgresql - 无法使用Docker Compose与Wordpress建立postgres连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60495831/

相关文章:

java - 在JOOQ中实现batchMerge()

python - Docker Node :8. 16.0-alpine 错误:未找到:python2

docker - Docker 容器内的 Datadog 集成

django - docker 中主机的 localhost 和 postgres 之间的区别

apache - 为什么我收到错误 "You don' t have permission to access/on this server."?

java - 使用 JDBC 在 PostgreSQL 中批量插入

python - 在 Postgres 和 MySQL 之间自动转储和恢复数据

postgresql - 锁定 PostgreSQL 中的公共(public)组角色

windows - 适用于 Windows 的 Docker : corrupted files

docker - docker-compose up --build 与 docker-compose build && docker-compose up 有区别吗