failing to connect local Wordpress to SQL Workbench

Halo, I am following this guide to create a local Wordpress Setup: https://davidyeiser.com/tutorials/docker-wordpress-theme-setup which worked quite well, but now I am trying to connect with MYSQLWorkbench and it never works.

yml file:

version: '3'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  wordpress:
    depends_on:
      - db
    image: wordpress:5.1.1-php7.3-apache
    ports:
      - "9210:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    working_dir: /var/www/html
    volumes:
      - ./wp-content:/var/www/html/wp-content
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
volumes:
  db_data:

docker ps: cmd docker ps

my attempt to connect is as followed,

  1. starting MySQLWorkbench
  2. CTRL + U ("Connect to Database")
  3. filled all fields with "wordpress" connect to database

and then it always says: enter image description here

I have tried different combinations of passwords or ports like 33060, but couldn't get it to connect.

Any Idea what I am missing?

1 answer

  • answered 2021-04-21 11:34 Zoli Szabó

    You need to expose the port 3306 of the db container instance.

    version: '3'
    
    services:
      db:
        image: mysql:5.7
        ports:
          - "3306:3306" <-- this is the important part here!
        volumes:
          - db_data:/var/lib/mysql
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: somewordpress
          MYSQL_DATABASE: wordpress
          MYSQL_USER: wordpress
          MYSQL_PASSWORD: wordpress
    ...