5

Is there any way to have bidirectional communication between docker containers on AWS Beanstalk?

The stack im trying to get working is pretty standard: Varnish -> Nginx -> PHP-FPM.

I am using the links specification to specify that nginx should find the hostname "php-app". Nginx finds the php-app hostname, so that works. However I also need the "php-app" to be able to resolve hostname "varnish" so the "php-app" can send PURGE requests for cache invalidation.

Basically now there is only this communication that works:

[varnish:80] -> [nginx:8080] -> [php-app]

However this should be working:

[varnish:80] -> [nginx:8080] -> [php-app] ---PURGE---> [varnish:80]

The php-app basically only needs to know about the IP of the varnish host, however that seems to be impossible.

I know that I can also get the varnish container ip from the HOST, but i want to do the same just from the php-app container:

VARNISH_HASH=`docker ps | grep varnish | sed 's/\|/ /' | awk '{print $1}'`
VARNISH_IP=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' $VARNISH_HASH`

I also tried adding links to the php-app container, but that resulted in errors when deploying, I guess it's because there are then circular dependencies:

"links": [
    "varnish"
]

My relevant Dockerrun.aws.json (container deifinition file) looks like this:

{
  "AWSEBDockerrunVersion": 2,
  "volumes": [ 
      .....
  ],
  "containerDefinitions": [
    {
      "name": "nginx-proxy",
      "image": "nginx",
      "essential": true,
      "memory": 128,
      "links": [
        "php-app"
      ],
      "portMappings": [
        {
          "hostPort": 8080,
          "containerPort": 8080
        }
      ],
      "environment": [
        {
          "name": "NGINX_PORT",
          "value": "8080"
        }
      ],
      "mountPoints": [ .... ]
    },
    {
      "name": "varnish",
      "hostname": "varnish",
      "image": "newsdev/varnish:4.1.0",
      "essential": true,
      "memory": 128,
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80
        }
      ],
      "links": [
        "nginx-proxy",
        "php-app"
      ],
      "mountPoints":  [ .... ]
    },
    {
      "name": "php-app",
      "image": "peec/magento2-php-fpm-aws",
      "essential": true,
      "memory": 1024,
      "environment": [
      ],
      "mountPoints":  [ .... ]
    }
  ]
}
Petter Kjelkenes
  • 1,605
  • 1
  • 19
  • 25
  • 1
    Did you find the answer? I'm searching for something similar, but I have the impression that with multicontainer docker on the same instance, you don't need to use the "links" parameter. What was the solution? – Florin Vistig Jul 03 '17 at 14:35
  • Looks like the links are unidirectional per [this answer](https://stackoverflow.com/questions/49943585/multicontainer-docker-aws-link-is-one-way). – opeonikute May 18 '21 at 12:40

0 Answers0