6

I have created a local docker wordpress instance and I am trying to connect to the database with a SQL Client (in my case TablePlus) but I am having trouble.

I created the docker containers from a docker-compose.yml file shown here:

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:latest
     ports:
       - "8028:80"
       - "8029:8029"

     volumes:
       - ./themes/travelmatic:/var/www/html/wp-content/themes/yadayada


     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       VIRTUAL_HOST: leasepilot.local

volumes:
    db_data:

I have tried any comibindation of wordpress and somewordpress in these fields: enter image description here

I also have the option to connect over SSH but I don't feel I would need to do that?

1) What is the best way to debug this type of issue? 2) What are the creds? lol

1
  • 1
    Without a ports: declaration, your database will be inaccessible from outside of Docker. Finding the credentials is left as an exercise.
    – David Maze
    Aug 8, 2019 at 11:30

2 Answers 2

21

There is another bit of information that should be added to the Praveen answer. If you have already mysql installed locally, on your computer/laptop, settings the db ports to:

- "3306:3306" 

it won't work because TablePlus will connect to your local mysql instance. Instead you should set your Docker mysql on a different published port and access that from TablePlus.

For example, set these ports on your Dockerfile (published port is 3356):

"3356:3306"

Then set the same port on TablePlus: enter image description here

14

Just as David has suggested in his comment, you need to add port mapping in docker-compose.yml. So, your modified docker-compose.yml would be something like this:

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
     ports:
       - "3306:3306"   
   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8028:80"
       - "8029:8029"

     volumes:
       - ./themes/travelmatic:/var/www/html/wp-content/themes/yadayada


     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       VIRTUAL_HOST: leasepilot.local

volumes:
    db_data:

And you have already provided the creds in the docker-compose.yml in environment variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.