Hello I'm trying to run two different MySQL versions as docker containers, however when I want to connect a second Wordpress blog, I'm greeted with the error message: Error establishing a database connection.
In the container logs everything is looking fine and I did change the network section and ports in my docker-compose.yml, but from looking at the container information I see that the MySQL container is still using 3306/tcp as port, even though I changed it with the environment variable MYSQL_TCP_PORT: 3307 and it is using this one as well.
Running two independent setups is mandatory. Thank you for your replies!
docker ps
3306/tcp, 33060/tcp, 0.0.0.0:3307->3307/tcp, :::3307->3307/tcp
docker-compose.yml
Credentials are sanitized
version: "3"
networks:
test:
name: test
ipam:
driver: default
config:
- subnet: 192.168.99.0/24
ip_range: 192.168.99.0/26
gateway: 192.168.99.1
attachable: true
services:
db2:
image: mysql:8.0.36
command: --default-authentication-plugin=mysql_native_password
container_name: MySQL2
environment:
MYSQL_ROOT_PASSWORD: 1234
MYSQL_ONETIME_PASSWORD: True
MYSQL_USER: test
MYSQL_PASSWORD_FILE: 1234
MYSQL_DATABASE: db2
MYSQL_TCP_PORT: 3307
volumes:
- /Wordpress/MySQLTest/:/var/lib/mysql
ports:
- 3307:3307
networks:
- test
wordpress:
depends_on:
- db2
image: wordpress:6.4.0-php8.0-apache
container_name: Wordpress2
ports:
- "18888:80"
environment:
WORDPRESS_DB_HOST: db_dev:3307
WORDPRESS_DB_USER: test
WORDPRESS_DB_PASSWORD: 1234
WORDPRESS_DB_NAME: db2
volumes:
- /WordpressTest:/var/www/html
networks:
- test
I did some trial & error testing using the appropriate environment variable or without it and change the port mapping.