1

I found many resolved topics about my issue but I still do not manage to fix it. It might be another issue or most probably have I not manage to understant what was going wrong. After weeks of tests, I do try to ask publicly for some support.

I'm trying to set up a wordpress on my personal server (Ubuntu 22.04).

Below is my docker-compose file:


version: '3'

services:
  wp-db:
    container_name: wp-mysql_container
    image: mysql:latest
    restart: unless-stopped
    environment:
      TZ: "Europe/Paris"
      MYSQL_ROOT_PASSWORD: ZZZZ
      MYSQL_USER: mywpuser
      MYSQL_DATABASE: mywpdb
      MYSQL_PASSWORD: XXXX
      MYSQL_TCP_PORT: 3307
    volumes:
      - ./wp-db_data:/var/lib/mysql
    ports:
      - 3307:3307
  
  wordpress:
    container_name: wordpress_container
    image: wordpress:latest
    restart: always
    depends_on:
      - wp-db
    ports:
      - 8082:80
    environment:
      WORDPRESS_DB_HOST: wp_db:3307
      WORDPRESS_DB_USER: mywpuser
      WORDPRESS_DB_PASSWORD: XXXX
      WORDPRESS_DB_NAME: mywpdb
    volumes:
      - ./wordpress:/var/www/html
      - ./wordpress_logs:/var/log/apache2

  wp-phpmyadmin:
    container_name: wp-phpmyadmin_container
    image: phpmyadmin:latest
    depends_on:
      - wp-db
    links: 
      - wp-db:wp-db
    ports: 
      - 8083:80
    environment:
      UPLOAD_LIMIT: 100000000
    restart: unless-stopped

volumes:
  wordpress:
  wordpress_logs:
  wp-db:
  wp-db_data:

When I try to reach for the wordpress of the phpmyadmin, I get the error message " Database Error : Error establishing a database connection"

Any help would be appreciated, thanks

I tried to follow those related topics:

Among many others...

EDIT: 2023/10/09 Now my docker-compose is as such and is working:

version: '3.8'
services:
  wordpress:
    container_name: wordpress_container
    image: wordpress:latest
    restart: always
    ports:
      - 8082:80
    environment:
      WORDPRESS_DB_HOST: wp_db_mysql
      WORDPRESS_DB_USER: qqqqqqqqqqq
      WORDPRESS_DB_PASSWORD: aaaaaaaaaaaaaa
      WORDPRESS_DB_NAME: yyyyyyyyyyy
    volumes:
      - wp_data:/var/www/htmlqsdgjuytac
  wp_db_mysql:
    container_name: wp_mysql_container
    image: mysql:5.7
    restart: always
    ports:
      - 3307:3307
    environment:
      MYSQL_DATABASE: yyyyyyyyyyy
      MYSQL_ROOT_PASSWORD: bbbbbbbbbb
      MYSQL_USER: qqqqqqqqqqq
      MYSQL_PASSWORD: aaaaaaaaaaaaaa
    volumes:
      - db_data:/var/lib/mysql
  wp_phpmyadmin:
    container_name: wp_phpmyadmin_container
    image: phpmyadmin/phpmyadmin:latest
    depends_on:
      - wp_db_mysql
    ports:
      - 8083:80
    restart: always
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3307
      PMA_ARBITRARY: 1
volumes:
  wp_data:
  db_data:

However, when I try to change the MYSQL_PASSWORD changing all "aaaaaaaaaaaaaa" to "nlkjazjeuzagq". I get again the error message. I tried:

  • docker-compose up -d
  • docker-compose down && docker image prune -af followed by docker-compose up -d.

Obviously I can't believe "aaaaaaaaaaaaaa" is the only password acceptable but I do not manage to re-initialiaze it.

4
  • 1
    The standard MySQL port number is 3306, not 3307. Does changing the port number to 3306 everywhere it appears in the file help? (The first ports: number can be different but isn't used in this particular setup.) If not, is there any more to the error message that might suggest how it's failing to connect? Commented Oct 3, 2023 at 10:34
  • Thanks David. 3306 is already used for another service, a LAMP server. I do not know if I should have "ports: 3307:3307" or ports: "3307:3306" tbh. I am a bit reluctant to kill my LAMP (and unsure yet how to) to pass everything to 3306. I do not know how/where to get more details about my error message. Commented Oct 3, 2023 at 10:46
  • ports: ['3307:3306'] will map the non-conflicting host port 3307 to the standard database port 3306 inside the container. Since each container otherwise has an isolated network environment, it's fine for the container to use the standard port even if you have other similar database containers or a database on the host. Commented Oct 3, 2023 at 10:48
  • I kept "MYSQL_TCP_PORT: 3307", changed to "ports: - 3307:3306" and changed "WORDPRESS_DB_HOST: wp_db". Is that the changes you had in mind? I still get the same error message unfortunately. Commented Oct 3, 2023 at 10:58

1 Answer 1

0

I'm in the same journey here, and mine WP just started working. See my code below.

Please note that the infamous message Error establishing a database connection may still occur: even though docker says "done", if you immediately go to the browser you'll get that message. In my case, I have to wait ~5 seconds and then it accepts connection (before that, the message appears).

Also, I've noticed that people suggest mysql:5.7 instead, so I would advise you to change that (seems to me that other versions (8) are applied at Oracle enterprise systems).

version: '3.8'
services:
  wordpress:
    container_name: wordpress
    image: wordpress:latest
    restart: always
    ports:
      - 9010:80
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_USER: qqqqqqqqqqq
      WORDPRESS_DB_PASSWORD: aaaaaaaaaaaaaa
      WORDPRESS_DB_NAME: yyyyyyyyyyy
    volumes:
      - wp_data:/var/www/html
  mysql:
    container_name: mysqlWordpress
    image: mysql:5.7
    restart: always
    ports:
      - 3306:3306
    environment:
      MYSQL_DATABASE: yyyyyyyyyyy
      MYSQL_ROOT_PASSWORD: bbbbbbbbbb
      MYSQL_USER: qqqqqqqqqqq
      MYSQL_PASSWORD: aaaaaaaaaaaaaa
    volumes:
      - db_data:/var/lib/mysql
  phpmyadmin:
    container_name: phpmyadmin
    image: phpmyadmin/phpmyadmin:latest
    depends_on:
      - mysql
    ports:
      - 9012:80
    restart: always
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3307
      PMA_ARBITRARY: 1
volumes:
  wp_data:
  db_data:
Sign up to request clarification or add additional context in comments.

11 Comments

Many thanks rd1218. I did manage to use your code and it worked. Now I can't figure out how to change the password (see my edit).
Maybe this is the case for another question instead? In my opinion, the original one seems correctly answered (and should be marked as the answer). Anyway, if you couldn't work with the inicial container, just remove it (docker rm -f <id>) and proceed with a new one.
In fact, the phpmyadmin still refuse to connect to the data base. I do not know if it's an issue of mapping the connection (I doubt that) or a login issue that might be linked to the fact that I can't change the mysql password and user...
Please remove both PMA_HOST: mysql and PMA_PORT: 3307 and have a try. Let me know then I will check to update the answer. For reference, this is my working command: docker container run -d --name phpMyAdmin --restart always -e PMA_ARBITRARY=1 -p 9000:80 --link mysql phpmyadmin/phpmyadmin:latest.
rd1218, sorry for the late reply, I was travelling. Indeed, removing PMA_PORT was the solution! Congratulation. I still do not manage to change your login parameters though. I believe I should wipe out everything beyond just killing the container but I do not find the correct command
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.