I’m using nginx-proxy from J. Wilder in front of multiple website containers. Now I would like to create a wordpress contain behind the nginx-proxy.
The following docker-compose file works in principle. The domain name is reachable and requests are forwarded to wordpress container. However, Wordpress outputs an page with the error “Error establishing a database connection” so somehow Wordpress can’t reach the database.
version: '3.1'
services:
app:
container_name: mypagename_blog
image: wordpress
depends_on:
- db
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=mysqluser
- WORDPRESS_DB_PASSWORD=password
- WORDPRESS_DB_NAME=wordpress_db
- VIRTUAL_HOST=mypagename.com
- LETSENCRYPT_HOST=mypagename.com.
- LETSENCRYPT_EMAIL=contact@mypagename.com
volumes:
- app:/var/www/html
restart: unless-stopped
expose:
- 80
db:
image: mysql:8.0
restart: always
environment:
MYSQL_DATABASE: wordpress_db
MYSQL_USER: mysqluser
MYSQL_PASSWORD: password
MYSQL_RANDOM_ROOT_PASSWORD: randompassword
volumes:
- db:/var/lib/mysql
expose:
- 3306
- 33060
volumes:
app:
db:
networks:
default:
external:
name: nginx-proxy
docker network inspect nginx-proxy
show all containers are in the network.
I’ve manually verified that the login mysql credentials in the db container are correct.
The container log does not show any error.
At the moment I’m not sure if the value of the environment variable WORDPRESS_DB_HOST is correct, because the container name is later used in wp-config.php and probably cannot be resolved correctly.
What can I do to narrow down the problem?