Docker Community Forums

Share and learn in the Docker community.

Error estabilishing database connection Docker

I was following a guide online, on how to set up a wordpress development environment.

Everything goes well until I try to visit the url I set up into my hosts file, to avoid writing localhost:8080 as it’s said into the guide.

When I try to visit http://dev.local I get Error establishing a database connection

My folder structure is this:

  • Docker
    • proxy
      • docker-compose.yml
    • test
      • docker-compose.yml

These are the two files I use:

—PROXY—

version: '3.7'

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    restart: always
    ports:
      - 80:80
      - 3306:3306
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

networks:
  default:
    external:
      name: proxy

—WP/mySQL/PHPMyAdmin—

version: "3.7"

services:

  mysql:
    image: mysql:latest
    restart: always
    ports: 
      - 8081:3306
    environment:
      MYSQL_USER: wordpress
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_PASSWORD: wordpress     
    networks:
      - backend

  wordpress:
    depends_on:
      - mysql
    image: wordpress
    ports:
      - 8080:80
    restart: always
    volumes: 
      - ./:/var/www/html/wp-content
    environment: 
      VIRTUAL_HOST: dev.local
      VIRTUAL_PORT: 8080
      WORDPRESS_DB_HOST: mysql:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    networks:
      - frontend
      - backend

  phpmyadmin:
    depends_on:
      - mysql
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - 8082:81
    environment: 
      PMA_HOST: mysql
      MYSQL_ROOT_PASSWORD: wordpress
    networks:
      - backend
  
networks:
  backend:
  frontend:
    external:
      name: proxy