This is my first blog post regarding my ventures into Docker, the immensely popular containerization platform.
Docker is great in many regards, but one of the first problems occurred when I had to rename my WordPress site and I needed to check inside the database to see whether or not the URLs were updated inside the database.
Obviously, one solution is to do a docker exec command and access MySQL right inside the container, but I needed a more efficient and long term solution.
Here are the steps that are need to make this work:
In your docker-compose.yml, ensure that you map a port on the host machine to that inside the container.
db:
image: mysql:8.0
restart: always
ports:
- 43306:3306
...the remainder of your configuration
If your docker container is already running, rebuild the container so that the configuration takes effect.
In MySQL Workbench, set the MySQL Hostname to 127.0.0.1, not the IP of the docker container and also the change the port to the one that you’ve specified in the previous step.
Once that’s done, you should be all ready to go and access your database! Happy Docker adventuring!