Last active
March 1, 2018 22:48
-
-
Save funseiki/12a0cc9c32e6b8aab31cb0d1a6f0f7eb to your computer and use it in GitHub Desktop.
Docker Compose Network Interaction Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3 | |
COPY . /app | |
WORKDIR /app | |
RUN pip install -r requirements.txt | |
ENV FLASK_APP=/app/app.py | |
ENTRYPOINT ["flask", "run"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requests | |
flask |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment