Wordpress a postgres with docker-compose

So I tried to make a docker container with wordpress & postgres using the ntninja/wordpress-postgresql image but it still trie to use MySQL to connect wordpress to the db.

Here is my docker-compose.yml

version: '3.8'

services:

  wordpress:
    depends_on:
      - "postgres"
    image: ntninja/wordpress-postgresql:latest
    restart: always
    ports:
      - 80:80
    environment:
      WORDPRESS_DB_HOST: postgres
      WORDPRESS_DB_USER: postgres
      WORDPRESS_DB_PASSWORD: postgres
      WORDPRESS_DB_NAME: postgres
    volumes:
      - ./wp:/var/www/html

  postgres:
    image: postgres:10.5
    restart: always
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    ports:
      - '5432:5432'
    volumes: 
      - ./postgres-data:/var/lib/postgresql/data

volumes:
  db:

and the result when i do sudo docker-compose up:

I’m currently using wsl2 with windows 10.

My guess is that you have a local config in your ./wp folder which you mounted into the container and overwrote the db.php which sets the DB_DRIVER variable.to be psql.

Thank you for your response.
My db.php didn’t seemed to be overwriten because it looks like this :

I have an update ! I just waited and now it tries to connect to postgres, but didn’t succed :


even though I have the same connection infos for both wordpress & postgres :

    environment:
      WORDPRESS_DB_HOST: postgres
      WORDPRESS_DB_USER: postgres
      WORDPRESS_DB_PASSWORD: postgres
      WORDPRESS_DB_NAME: postgres

and for postgres:

environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres

The dbd part of my wp-config looks like this :

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'postgres');

/** MySQL database username */
define('DB_USER', 'postgres');

/** MySQL database password */
define('DB_PASSWORD', 'postgres');

/** MySQL hostname */
define('DB_HOST', 'postgres');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');```

Well, yes, it tries to connect to the database server called “postgres”, but it tries to do that as if it were a MySQL server.

Are you sure that this is the file that WordPress loads? If you checked it only on the host, try to use docker exec to get inside the container, find the file where ou expect it to be, and read the content. For example:

head -n 17 db.php

to read the first 17 lines.Then change something on the host and check the content from the container again.

Then you can temporarily delete the whole content of the file without deleting the file itself. Try to connect again and if it gives you the same message, then there is an other file somewhere where the configuration comes from and the database driver is not set.

If you get an other error mesage, for example “undefined constant”, then I have no other explanation then a bug in the image and you should contact the maintainer of the image.