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 user permissions explanation
  • Apache Mesos + Docker + Karaf Cellar Cluster
  • spring-cloud-config in docker-compose https certificate not found
  • Generate all locales in a docker image
  • How can I expose the dynamic $PORT from Heroku in a Dockerfile?
  • Can't acces docker container by IP address
  • Proxying request from webpack 2 using webpack-dev-server to backend api in docker containers
  • How is load balancing done in Docker-Swarm mode
  • docker current not installed - bash on ubuntu on windows 10
  • named docker volume not updating using docker-compose
  • Bash command to return a free port
  • Using COPY on dockerfile for apache build
  • 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.