Answers: <p>I'm still fairly new to the Docker game, too, but I've got a few little projects that I do exactly what you are asking about. Through my own experience with trial &amp; error (mostly error...) I would suggest using a docker-compose.yml with your network set to static internal IPs so each container will have predictable, repeatable results and IPs that you can configure your containers to communicate across.</p>
  <p>I'm not familiar with <code>BaseX</code> but I have a sample situation using docker-compose <code>version: &quot;3.7&quot;</code> here that could easily run multiple apps and/or be added to or repurposed to fit your hypothetical.</p>
  <p>This example docker-compose has the following:</p>
  <ul>
  <li><p>A separate container for populating my <code>app-volume</code> volume with the contents of a public GitHub repo.</p>
  </li>
  <li><p>An Apache Web Server container with PHP-FPM enabled for a &quot;selective backend&quot; that gets built from a Dockerfile in the ~/dockerbuild directory.</p>
  </li>
  <li><p>An nginx web server container used as a reverse proxy for all things PHP to be passed to Apache (but serves &amp; caches pretty much everything else).</p>
  </li>
  <li><p>A MariaDB container in the mix for the app DB that I populate with a mysqldump file after the app gets built.</p>
  </li>
  </ul>
  <p>This is a slimmed down version of my docker-compose.yml, so note that you can add a variety of things like <code>healthcheck:</code> and <code>command:</code> to fit your needs.</p>
  <p>You execute with <code>docker-compose up -d --build</code> to both build and start your app in one command (but you'll probably want to create your own ba(.sh) file that you execute afterwards, too for those important finishing touches).</p>
  <p>Take notice of <code>static-network</code>. And while I am using named volumes in the example, that's just a preference of mine.</p>
  <pre><code>version: &quot;3.7&quot;
  
  services:
  
    github_repo_clone:
      image: debian:latest
      container_name: github_repo_clone
      networks: 
        static-network:
          ipv4_address: 172.20.0.254
  
      command: bash -c &quot;
          apt-get update &amp;&amp; 
          apt-get install git -y &amp;&amp;
          rm -rf examplerepo &amp;&amp;
          git clone https://github.com/exampleuser/examplerepo.git &amp;&amp;
          rm -rf /var/www/vhosts/exampleuser/examplerepo &amp;&amp;
          mkdir -p /var/www/vhosts/exampleuser/examplerepo &amp;&amp;
          cp -rapv examplerepo/* /var/www/vhosts/exampleuser/examplerepo &amp;&amp;
          rm -rf examplerepo &amp;&amp;
          tail -f /dev/null
        &quot;
      volumes:
       - app-volume:/var/www/vhosts
  
    apache_php-fpm_backend:
      container_name: debian-build-demo0
      build: ~/dockerbuild
      ports:
       - &quot;8080:8080&quot;
      networks:
        static-network:
          ipv4_address: 172.20.0.2
      volumes:
       - app-volume:/var/www/vhosts
  
  
    nginx_rp:
      image: nginx:latest
      container_name: nginx-build-demo0
      ports:
       - &quot;80:80&quot;
       - &quot;443:443&quot;
      networks:
        static-network:
          ipv4_address: 172.20.0.3
      volumes:
       - app-volume:/var/www/vhosts
  
    mariadb:
      restart: always
      image: mariadb:latest
      container_name: mariadb-build-demo0
      ports:
       - &quot;3306:3306&quot;
      networks:
        static-network:
          ipv4_address: 172.20.0.10
      environment:
       - MYSQL_ROOT_PASSWORD=4007p@$$w04d
       - MYSQL_USER=dbusernamegoeshere
       - MYSQL_PASSWORD=@p@$$w04d
       - MYSQL_DATABASE=dbnamegoeshere
      volumes:
       - app-volume:/var/www/vhosts
      healthcheck:
        test: [&quot;CMD&quot;, &quot;mysqladmin&quot; ,&quot;ping&quot;, &quot;-h&quot;, &quot;localhost&quot;]
        timeout: 10s
        retries: 5
  
  volumes:
    app-volume:
  #    external: true
  
  networks:
    static-network:
      driver: bridge
      ipam:
        driver: default
        config:
         - subnet: 172.20.0.0/16
  
  </code></pre>
  <p>My clean up command when I take the app down is kind of ugly, but not terribly difficult to read and goes something like this:
  <code>docker-compose down -v ; docker rmi -f dockerbuild_apache_php-fpm_backend:latest mariadb:latest nginx:latest debian:latest ; docker rmi -f $(docker images -q --filter &quot;dangling=true&quot;) ; docker rmi -f $(docker images -q --filter label=stage=intermediate) ; docker volume prune -f; </code></p>
  <p>I think each &quot;independent app&quot; could (and probably should) have its own docker-compose and/or Dockerfiles, but you may find synergies with certain Dockerfiles that you can create custom <code>command:</code> instructions for (such as the git_repo_clone example) to be used &amp; shared across multiple &quot;apps&quot;.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-09-23T03:01:30.953Z
Answers: 2020-09-25T16:21:02.590Z
Answers: 2020-09-25T16:21:02.590Z
Answers: CoolElectricity
Body: <p>In &quot;What is a container?&quot; the <code>docker</code> docs show the following <a href="https://www.docker.com/resources/what-container" rel="nofollow noreferrer">nifty</a> image:</p>
  <p><a href="https://i.sstatic.net/SYqVD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/SYqVD.png" alt="docker" /></a></p>
  <p>For my scenario I have only App A and App B; let's designate them Alice and Bob.  How do Alice and Bob communicate, generally and specifically?  Using the KISS principle, concretely I'm using <code>MySQL</code> and <code>BaseX</code> from the docker hub.</p>
  <p>The notion being for an <code>xquery</code> file residing on the host, which is then sent to the <code>BaseX</code> container for execution.  This specific query is actually <code>SQL</code>, so the <code>MySQL</code> container will need to be queried for the result.</p>
  <p>Does this necessitate port forwarding or other <a href="https://docs.cloudfoundry.org/concepts/understand-cf-networking.html" rel="nofollow noreferrer">networking</a> approaches?  Volumes?  Does this require an additional <a href="https://baldbeardedbuilder.com/posts/communication-between-containers-using-docker-compose-in-windows/" rel="nofollow noreferrer">compose</a> file composed of, in turn, <code>MySQL</code> and <code>BaseX</code>?</p>
  <p>No doubt there are many possible approaches.  What's the most pragmatic, from a learning perspective?  Conceptually light, with a gradual learning curve.</p>
  <p>One <a href="https://www.linode.com/docs/applications/containers/docker-container-communication/" rel="nofollow noreferrer">approach</a> seems to utilize bridge networking:
  <a href="https://i.sstatic.net/YEXR6.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YEXR6.jpg" alt="simple" /></a></p>
  <p>Taking advantage of the fact that the containers can <a href="https://codeblog.dotsandbrackets.com/communication-between-docker-containers/" rel="nofollow noreferrer">see</a> each other.</p>
  <p>This doesn't seem to me <a href="https://docs.microsoft.com/en-us/dotnet/architecture/microservices/architect-microservice-container-applications/communication-in-microservice-architecture" rel="nofollow noreferrer">related</a> to <code>REST</code>ful web services.</p>
  <hr />
  <p>Looking at related questions, this might touch on a reverse proxy.</p>
  
Comments: CC BY-SA 4.0
Comments: 2020-09-22T22:48:05.793Z
Comments: see also:  https://stackoverflow.com/q/41130421/4531180
Comments: Nicholas Saunders
Tags: <docker><docker-compose><containers><databases><volume>
Title: How to Connect Docker Containers?
UserDisplayName: Nicholas Saunders
ThreadText: # How to Connect Docker Containers?
  
  (Asked by: username_0 on 2020-09-22)
  
  In "What is a container?" the `docker` docs show the following [nifty](https://www.docker.com/resources/what-container) image:
  
  [![docker](https://i.sstatic.net/SYqVD.png)](https://i.sstatic.net/SYqVD.png)
  
  For my scenario I have only App A and App B; let's designate them Alice and Bob. How do Alice and Bob communicate, generally and specifically? Using the KISS principle, concretely I'm using `MySQL` and `BaseX` from the docker hub.
  
  The notion being for an `xquery` file residing on the host, which is then sent to the `BaseX` container for execution. This specific query is actually `SQL`, so the `MySQL` container will need to be queried for the result.
  
  Does this necessitate port forwarding or other [networking](https://docs.cloudfoundry.org/concepts/understand-cf-networking.html) approaches? Volumes? Does this require an additional [compose](https://baldbeardedbuilder.com/posts/communication-between-containers-using-docker-compose-in-windows/) file composed of, in turn, `MySQL` and `BaseX`?
  
  No doubt there are many possible approaches. What's the most pragmatic, from a learning perspective? Conceptually light, with a gradual learning curve.
  
  One [approach](https://www.linode.com/docs/applications/containers/docker-container-communication/) seems to utilize bridge networking:
  [![simple](https://i.sstatic.net/YEXR6.jpg)](https://i.sstatic.net/YEXR6.jpg)
  
  Taking advantage of the fact that the containers can [see](https://codeblog.dotsandbrackets.com/communication-between-docker-containers/) each other.
  
  This doesn't seem to me [related](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/architect-microservice-container-applications/communication-in-microservice-architecture) to `REST`ful web services.
  
  ---
  
  Looking at related questions, this might touch on a reverse proxy.
  
  **Tags:** docker, docker-compose, containers, databases, volume
  
  > **Comments:**
  > **username_0**: see also:  https://stackoverflow.com/q/41130421/4531180  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-09-23. Score: 1 | Accepted answer
  
  I'm still fairly new to the Docker game, too, but I've got a few little projects that I do exactly what you are asking about. Through my own experience with trial & error (mostly error...) I would suggest using a docker-compose.yml with your network set to static internal IPs so each container will have predictable, repeatable results and IPs that you can configure your containers to communicate across.
  
  I'm not familiar with `BaseX` but I have a sample situation using docker-compose `version: "3.7"` here that could easily run multiple apps and/or be added to or repurposed to fit your hypothetical.
  
  This example docker-compose has the following:
  
  * A separate container for populating my `app-volume` volume with the contents of a public GitHub repo.
  * An Apache Web Server container with PHP-FPM enabled for a "selective backend" that gets built from a Dockerfile in the ~/dockerbuild directory.
  * An nginx web server container used as a reverse proxy for all things PHP to be passed to Apache (but serves & caches pretty much everything else).
  * A MariaDB container in the mix for the app DB that I populate with a mysqldump file after the app gets built.
  
  This is a slimmed down version of my docker-compose.yml, so note that you can add a variety of things like `healthcheck:` and `command:` to fit your needs.
  
  You execute with `docker-compose up -d --build` to both build and start your app in one command (but you'll probably want to create your own ba(.sh) file that you execute afterwards, too for those important finishing touches).
  
  Take notice of `static-network`. And while I am using named volumes in the example, that's just a preference of mine.
  
  ```
  version: "3.7"
  
  services:
  
    github_repo_clone:
      image: debian:latest
      container_name: github_repo_clone
      networks: 
        static-network:
          ipv4_address: 172.20.0.254
  
      command: bash -c "
          apt-get update && 
          apt-get install git -y &&
          rm -rf examplerepo &&
          git clone https://github.com/exampleuser/examplerepo.git &&
          rm -rf /var/www/vhosts/exampleuser/examplerepo &&
          mkdir -p /var/www/vhosts/exampleuser/examplerepo &&
          cp -rapv examplerepo/* /var/www/vhosts/exampleuser/examplerepo &&
          rm -rf examplerepo &&
          tail -f /dev/null
        "
      volumes:
       - app-volume:/var/www/vhosts
  
    apache_php-fpm_backend:
      container_name: debian-build-demo0
      build: ~/dockerbuild
      ports:
       - "8080:8080"
      networks:
        static-network:
          ipv4_address: 172.20.0.2
      volumes:
       - app-volume:/var/www/vhosts
  
    nginx_rp:
      image: nginx:latest
      container_name: nginx-build-demo0
      ports:
       - "80:80"
       - "443:443"
      networks:
        static-network:
          ipv4_address: 172.20.0.3
      volumes:
       - app-volume:/var/www/vhosts
  
    mariadb:
      restart: always
      image: mariadb:latest
      container_name: mariadb-build-demo0
      ports:
       - "3306:3306"
      networks:
        static-network:
          ipv4_address: 172.20.0.10
      environment:
       - MYSQL_ROOT_PASSWORD=4007p@$$w04d
       - MYSQL_USER=dbusernamegoeshere
       - MYSQL_PASSWORD=@p@$$w04d
       - MYSQL_DATABASE=dbnamegoeshere
      volumes:
       - app-volume:/var/www/vhosts
      healthcheck:
        test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
        timeout: 10s
        retries: 5
  
  volumes:
    app-volume:
  #    external: true
  
  networks:
    static-network:
      driver: bridge
      ipam:
        driver: default
        config:
         - subnet: 172.20.0.0/16
  
  ```
  
  My clean up command when I take the app down is kind of ugly, but not terribly difficult to read and goes something like this:
  `docker-compose down -v ; docker rmi -f dockerbuild_apache_php-fpm_backend:latest mariadb:latest nginx:latest debian:latest ; docker rmi -f $(docker images -q --filter "dangling=true") ; docker rmi -f $(docker images -q --filter label=stage=intermediate) ; docker volume prune -f;`
  
  I think each "independent app" could (and probably should) have its own docker-compose and/or Dockerfiles, but you may find synergies with certain Dockerfiles that you can create custom `command:` instructions for (such as the git\_repo\_clone example) to be used & shared across multiple "apps".
  
  
  ---
  
  