How does network communication between 2 Docker Containers work?

I have two Docker Containers. How can can Container A communicate with Container B over TCP?

In my scenario: Container A runs Apache. Container B runs PHP-FPM. Apache needs to talk to PHP-FPM.

  • DOCKER installation ERROR “Internal error: Failed to expand shell folder constant ”userdocs" on Windows
  • Multiple Docker images in .gitlab-ci.yml
  • Passing bash code through the environment (for docker-compose)
  • Ubuntu Docker image broken out of the box?
  • Phusion Passenger http to https results in redirect loop
  • Docker stops immediately upon running - EOF error
  • docker: command not found with Jenkins build and publish plugin on Mac
  • concourse gradle java build CI
  • Profiling Java application in kubernetes
  • How to fix insecure-registry error on clients by updating the docker registry server
  • i don't manage to push a docker image into openshift docker registry
  • How to copy files in maven build that can be used at run time on Docker container?
  • One Solution collect form web for “How does network communication between 2 Docker Containers work?”

    I just answered that this morning 🙂

    Link to the answer (it talks about php-fpm and nginx, but the concept is the same for apache of course): https://stackoverflow.com/a/19997381/227887

    Long story short, you want to use container linking, a new feature as of 0.6.5 that permits to expose a port from a container to another.

    See also the official docker documentation : http://docs.docker.io/en/latest/examples/linking_into_redis/

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