1
votes

My application is split in two different applications (microservices?). One is deployed to CF as a docker container and another is deployed as a regular WAR file (grails application). The docker container is a Python/Flask application that exposes a REST API. The WebApp Uses this rest API.

Previously I had these applications as two separate docker containers and would execute them using the docker --link flag but now I'm looking to put these applications in Cloud Foundry. In the docker world I used to do the following.

docker run -d --link python_container -p 8080:8080 --name war_container war_image

The above command would create environment variables in war_container that would expose the ip address and port for the python_container. Using these environment variables I could communicate to the python_container from my WAR application. These environment variables would look like this:

PYTHON_CONTAINER_PORT_5000_TCP_ADDR=<ipaddr>
PYTHON_CONTAINER_PORT_5000_TCP_PORT=<port>

Question

Is it possible to do something similar in Cloud Foundry? I have the docker container already deployed in CF. How can I link the my WAR application such a way that the environment variables get created that get linked to the python_container as soon as I push the war file.

Currently I push the docker container to PCFDev using this:

cf push my-app -o 192.168.0.102:5002/my/container:latest

Then I push the war file using

cf push cf-sample -n cf-sample

The manifest.yml for cf-sample is:

---
applications:
  - name: cfsample
    memory: 1G
    instances: 1  
    path: target/cf-sample-0.1.war
    buildpack: java_buildpack
    services:
      - mysql
      - rabbitmq
1

1 Answers

2
votes

How would does the Docker way work if you had multiple instances of your Python app, and hence multiple IPs/ports?

For PCF, you could just have the Java app talk to your Python app "through the front door": https://my-python-app.local.pcfdev.io.

You can also try to discover your Python app's IP and port (see https://docs.run.pivotal.io/devguide/deploy-apps/environment-variable.html#CF-INSTANCE-IP for instance) and then pass these values to your Java app as environment variables, but this is a very brittle solution.

If you're interested in direct container-to-container networking, you might be interested in reading about and giving feedback on this proposal.