Skip to content

Instantly share code, notes, and snippets.

@funseiki
Last active March 1, 2018 22:48
Show Gist options
  • Save funseiki/12a0cc9c32e6b8aab31cb0d1a6f0f7eb to your computer and use it in GitHub Desktop.
Save funseiki/12a0cc9c32e6b8aab31cb0d1a6f0f7eb to your computer and use it in GitHub Desktop.
Docker Compose Network Interaction Example
import requests
from flask import Flask, request
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello from {}".format(request.host)
@app.route("/request/<int:port>")
def doPing(port):
ret = None
try:
location = "http://localhost:{}/".format(port)
ret = requests.get(location, timeout=5).content
except Exception as e:
ret = "Unable to retrieve: {}".format(e)
return ret
version: '3'
services:
receiver:
build: ./app
expose:
- 3000
ports:
- 3000:3000
command: "--host 0.0.0.0 --port 3000"
requester:
build: ./app
expose:
- 4000
ports:
- 4000:4000
command: "--host 0.0.0.0 --port 4000"
FROM python:3
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENV FLASK_APP=/app/app.py
ENTRYPOINT ["flask", "run"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment