I have a similar issue to Run MySQL on Port 3307 Using Docker Compose but either I can't see the wood for the trees or the solution here is not working.
I have the following docker-compose.yml file:
version: '3'
services:
db:
image: mysql:5.7
container_name: squirrels_db
volumes:
- db_data:/var/lib/docker/volumes/squirrels_db_data/_data
restart: always
ports:
# <Port exposed> : <MySQL Port running inside container>
- 3310:3306
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: mydb_user
MYSQL_PASSWORD: password
volumes:
- ./var/lib/docker/volumes/squirrels_db_data/_data
networks:
internal-net:
ipv4_address: 172.29.0.11
wordpress:
image: wordpress:latest
container_name: squirrels_web
depends_on:
- db
ports:
- 8000:80
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: mydb_user
WORDPRESS_DB_NAME: mydb_name
WORDPRESS_DB_PASSWORD: password
volumes:
- ./data/wp_content:/var/www/html/wp-content
- ./config/wordpress/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
networks:
nginx-proxy:
internal-net:
ipv4_address: 172.29.0.12
# Names our volume
volumes:
db:
networks:
nginx-proxy:
external:
name: nginx-proxy
internal-net:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.29.0.0/16
Note: I have changed usernames and passwords here and will eventually have them in a .env file
When I hit http://localhost:8000 I am seeing a WordPress delivered "Error establishing a database connection" message and the following in the log (from docker-compose logs):
PHP Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22 MySQL Connection Error: (2002) Connection refused
This now officially driving me nuts, not helped at all by just knowing I am missing something obvious! So, any observations or suggestions gratefully received
Thanks