How to send and receive data between docker containers?

1/19/2019

Suppose I want to create a Web app which consists of three different dockerized parts:

  1. Web Server (e.g. Nginx) for Frontend
  2. API built with GO
  3. Python Script which is run by 2. on demand

Eg. When a user visits example.com the static frontend is served, they click on a button which triggers a call to the API, the API in turn calls and waits for the result of a Python Script.

Would I set up RESTful Endpoints for 2. and 3.? If the API should be publicly available would I create another NGINX instance, so it would be NGINX and Go inside a single container? How would I „collect“ the result of the Python script for the API, with another NGINX instance inside the Python container? Wouldn't that violate the principles of Docker and drastically reduce maintainability as I‘d have to maintain every NGINX instance?

-- Alex Gogl
docker
dockerfile
kubernetes

1 Answer

1/19/2019

I see two ways to handle this:

  • Create a python web service instead of just a script and then you can call it directly and it can answer with the result (you might even get rid of the go api if all it's function is to forward the call)
  • If the python code has to be a script then it's basically part of the go web service and should be built into the same container
-- E.T.
Source: StackOverflow