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:
- Wordpress Docker "Error establishing a database connection"
- Docker Wordpress: Error establishing a database connection
- DOCKER and WordPress: Error establishing a database connection
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.
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?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.