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

  • Dockerfile RUN command taking a lot of disk space
  • Docker + WordPress + Traefik
  • How can I remove the Cmd entry from a Docker image configuration?
  • Docker - cannot connect to the Docker daemon
  • Add new Tomcat containers behind Apache with Docker
  • Can't run puma in daemon mode in docker
  • Could not initialize corosync configuration API error 12
  • meet Call to undefined function Xinax\LaravelGettext\bindtextdomain() error in LaravelProject
  • Swarm: Get Node Ip and Container IP from service
  • How do I set environment variables during the build in docker
  • How to edit files in stopped/not starting docker container
  • Files not getting added in docker workspace
  • 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:
    https://docs.docker.com/engine/userguide/networking/default_network/container-communication/

    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:

    https://docs.docker.com/engine/userguide/networking/dockernetworks/#an-overlay-network

    Here are the steps for setup

    https://docs.docker.com/engine/userguide/networking/get-started-overlay/

    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 https://github.com/weaveworks/weave.

    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.