How to connect WordPress and MySql running on independant containers

WordPress is running inside a Docker container on hostA and MySQL is running inside a Docker container on hostB. Is it possible to link these two containers to communicate to each other? Is this even possible to do something like this?

Any help on this is much appreciated as am pretty new to Docker

  • How to retrieve GOPATH from Docker container?
  • How to find css/js files on a server for specified application that uses docker
  • Listing all version numbers of docker image
  • Docker set container IP addr from DHCP/DNS automatically
  • Why doesn´t docker-compose env_file work but environment does?
  • Running docker commands in bash script leads to segmentation fault
  • Docker and Rails environments
  • Using sudo inside non-priviledged docker container not working
  • AspCore using Docker on Mac
  • GitLab-CI Multi Runner php composer cache
  • Why I can't rm docker image?
  • Is it possible to launch privileged docker containers on Amazon elasticbeanstalk?
  • 3 Solutions collect form web for “How to connect WordPress and MySql running on independant containers”

    I can not answer you question but there is a part in the documentation about this:

    You will find a section called: Communication between containers

    Yes this is possible with docker overlay network.

    The setup is not as easy as setting up a link or private network on the same host.
    You will have to configure a key value store to get this working.

    Here is the relevant docker documentation.

    An overlay network:

    Here are the steps for setup

    In my opinion, its not bad to isolate the app and database containers and connect outside the docker network. If you end up adding the key/value store like consul, you can always leverage the service discovery that comes along with it to dynamically discover the services.

    I would go for

    Weave Net creates a virtual network that connects Docker containers across multiple hosts and enables their automatic discovery.

    It might be overkill for your usecase. But it would be very helpful if you want to move the containers around in the future.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.