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": [ .... ]
}
]
}