Hi All, lately i try to learn the docker technology by dockerize my existing wordpress website. However, i found out all the tutorial out there are creating the database in the docker rather then connect to external database. I Done some research on docker network host, but still no ideal how to adapt it into my scenerio. For learning purpose, could anyone guide me on how to configure my docker-compose.yml to establish database connection to my wordpress website? below is my docker-compose.yml
The variable you need to change is the WORDPRESS_DB_HOST one, as you state, the current configuration is that there would be a container named “db” in the same network that it can use.
If you have an external, like, not the same server as docker is running on, you can simply change WORDPRESS_DB_HOST to an IP or host of the database server.
If the database is hosted on the same server, you have a couple of options:
Set WORDPRESS_DB_HOST to the IP of the server
Get the gateway IP of your docker network, and use that (the gateway ip will be the host)
set “network_mode” to “host”, in short, this means that the container will run as if it was a normal service on your server, meaning that you then can set WORDPRESS_DB_HOST to 127.0.0.1
hmm somehow still did not solve. I can see that they are in a bridge network. Ip’s are all good. But still Wordpress can’t connect to database of MySQL somehow.