Docker Community Forums

Share and learn in the Docker community.

Error establishing a database connection - running container

I need some help please. I am not sure what I am doing wrong. I have created a Wordpress image and container for a site I am building. When I do a docker-compose up -d the site comes up and i can access it. However when I run it as a container to test I get an error establishing a database connection.

Can anyone tell me what I may have done wrong or not added to my docker-compose.yml file. Could it be an environment variable issue?

I just need a nudge in the right direction. Any help will be appreciated.

The provided details are insufficient to understand the situation.
Please provide your docker-compose.yml.

So sorry, here is my docker-compose file. I am using a .env file for my variables. The issue occurs when i run this command: docker container run --publish 8000:80 --detach --name imagename:tag. I get the same message when i pull the image from Docker Hub into Azure Container Service when trying to publish my website.

version: ‘3.7’

networks:
delteqiscom:
volumes:
wp_data:

services:

Database

db:
image: mysql:5.7
volumes:
- wp_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: “{MYSQL_ROOT_PASSWORD}" MYSQL_DATABASE: "{MYSQL_DATABASE}”
MYSQL_USER: “{MYSQL_USER}" MYSQL_PASSWORD: "{MYSQL_PASSWORD}”
networks:
- delteqiscom

phpmyadmin

phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- ‘8080:80’
- ‘443:443’
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: “${MYSQL_ROOT_PASSWORD}”
networks:
- delteqiscom

Wordpress

wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- ‘8000:80’
restart: always
volumes: [’./:/var/www/html’]
environment:
WORDPRESS_DB_HOST: “{WORDPRESS_DB_HOST}" WORDPRESS_DB_USER: "{WORDPRESS_DB_USER}”
WORDPRESS_DB_PASSWORD: “{WORDPRESS_DB_PASSWORD}" WORDPRESS_DB_NAME: "{WORDPRESS_DB_NAME}”
networks:
- delteqiscom

Just to be sure: when you use image: wordpress:latest then this is the offical image from dockerhub and not a self created image that just happend to have the same tag as the official image?

Please provide the details of your .env file as well - only anonymize WORDPRESS_DB_PASSWORD.
I need to be able to see if all bits and pieces are “wired together correctly”.

Please provide ALL details required to get a full picture. If you realy did build your own image(s), provide the(ir) Dockerfile(s) and its entrypoint scripts.

Yes, I am using the Wordpress image form docker hub. Here is my .env file:

MYSQL_ROOT_PASSWORD=Password12345
MYSQL_DATABASE=delteqiscom_wp4
MYSQL_USER=delteqiscom_wp4
MYSQL_PASSWORD=Password12345

WORDPRESS_DB_HOST=db:3306
WORDPRESS_DB_USER=delteqiscom_wp4
WORDPRESS_DB_PASSWORD=*********
WORDPRESS_DB_NAME=delteqiscom_wp4