Loosie94
Loosie94

Reputation: 665

Docker WordPress image can't connect to database

I have an issue with a docker image.
I have just followed this tutorial to get custom local domains: https://medium.com/@francoisromain/set-a-local-web-development-environment-with-custom-urls-and-https-3fbe91d2eaf0

This seem to work good. But now I can not seem to connect to the Mysql database.
I'm using the WordPress image and my docker-compose.yml file looks like this:

version: '3.3'
services:
  db:
    image: mysql:5.7
    restart: unless-stopped
    volumes:
      - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: p4ssw0rd!

  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    expose:
      - 80
    environment:
      VIRTUAL_HOST: phpmyadmin.local
      VIRTUAL_PORT: 80
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: p4ssw0rd!

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - ./wp-content:/var/www/html/wp-content
    restart: always
    expose:
      - 80
    environment:
      VIRTUAL_HOST: domain.local
      VIRTUAL_PORT: 80
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_NAME: wp_name
      WORDPRESS_DB_USER: wp_user
      WORDPRESS_DB_PASSWORD: p4ssw0rd!
      WORDPRESS_TABLE_PREFIX: wp_
      WORDPRESS_DEBUG: 1

volumes:
    db_data: {}
networks:
  default:
    external:
      name: nginx-proxy

When I start running the container, the error I'm getting is this:

wordpress_error So now I know my WordPress container and proxy are working (domain.local), but the only thing missing is the connection to the database.

I think this has to do with the 'network' and that he simply can't find the database. But I have no idea how to connect it.

Hope one of you guys know what I'm doing wrong. Thanks in advance.

Upvotes: 0

Views: 486

Answers (1)

Loosie94
Loosie94

Reputation: 665

Okay, so I finally figured it out.
The WORDPRESS_DB_USER should be set to: root

Then everything will work.

Upvotes: 1

Related Questions