# Wordpress a postgres with docker-compose

**URL:** <https://forums.docker.com/t/wordpress-a-postgres-with-docker-compose/132071>\
**Category:** Compose\
**Created:** [November 25, 2022, 1:21pm UTC](https://forums.docker.com/t/wordpress-a-postgres-with-docker-compose/132071 "2022-11-25T13:21:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hfifre](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/hfifre/32/37662_2.png) [@hfifre](https://forums.docker.com/u/hfifre)\
**Post date:** [November 25, 2022, 1:21pm UTC](https://forums.docker.com/t/wordpress-a-postgres-with-docker-compose/132071/1 "2022-11-25T13:21:20Z")

</div>

So I tried to make a docker container with wordpress & postgres using the [ntninja/wordpress-postgresql](https://hub.docker.com/r/ntninja/wordpress-postgresql) image but it still trie to use MySQL to connect wordpress to the db.

Here is my docker-compose.yml

```nohighlight
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`:

 ![image](https://global.discourse-cdn.com/docker/original/3X/1/c/1c9ce984f9ce1599ae32b7be473044bafc3b4ce8.png)

I’m currently using wsl2 with windows 10.

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [November 27, 2022, 11:40am UTC](https://forums.docker.com/t/wordpress-a-postgres-with-docker-compose/132071/2 "2022-11-27T11:40:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hfifre](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/hfifre/32/37662_2.png) [@hfifre](https://forums.docker.com/u/hfifre)\
**Post date:** [November 28, 2022, 9:56am UTC](https://forums.docker.com/t/wordpress-a-postgres-with-docker-compose/132071/3 "2022-11-28T09:56:40Z")

</div>

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

 ![image](https://global.discourse-cdn.com/docker/original/3X/4/2/42164a214b9815265b8783e3099f0f13d1f75ac1.png)

---

<div class="post-metadata">

**Author:** ![hfifre](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/hfifre/32/37662_2.png) [@hfifre](https://forums.docker.com/u/hfifre)\
**Post date:** [November 28, 2022, 10:02am UTC](https://forums.docker.com/t/wordpress-a-postgres-with-docker-compose/132071/4 "2022-11-28T10:02:57Z")

</div>

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

 ![image](https://global.discourse-cdn.com/docker/original/3X/f/8/f8b6e3bd2972afbd96ae54ca48da961b36d843a2.png)  
even though I have the same connection infos for both wordpress & postgres :

```nohighlight
    environment:
      WORDPRESS_DB_HOST: postgres
      WORDPRESS_DB_USER: postgres
      WORDPRESS_DB_PASSWORD: postgres
      WORDPRESS_DB_NAME: postgres

```

and for postgres:

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

```

---

<div class="post-metadata">

**Author:** ![hfifre](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/hfifre/32/37662_2.png) [@hfifre](https://forums.docker.com/u/hfifre)\
**Post date:** [November 28, 2022, 10:11am UTC](https://forums.docker.com/t/wordpress-a-postgres-with-docker-compose/132071/5 "2022-11-28T10:11:53Z")

</div>

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

````php
// **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', '');```
````

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [November 28, 2022, 7:03pm UTC](https://forums.docker.com/t/wordpress-a-postgres-with-docker-compose/132071/6 "2022-11-28T19:03:30Z")

</div>

> [@hfifre](#):
>
> I just waited and now it tries to connect to postgres, but didn’t succed :

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.

> [@hfifre](#):
>
> My db.php didn’t seemed to be overwriten because it looks like this :

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![theflyingcoder](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/theflyingcoder/32/40114_2.png) [@theflyingcoder](https://forums.docker.com/u/theflyingcoder)\
**Post date:** [April 4, 2023, 12:57am UTC](https://forums.docker.com/t/wordpress-a-postgres-with-docker-compose/132071/7 "2023-04-04T00:57:52Z")

</div>

Just bumping this as I have the exact same issue.

Did you find a solution @hfifre?
