# Initialize a local git repository and add a new remote
git init
git remote add origin git@swarm:my-app
Code a basic Python web server:
./app.py
from flask import Flask
from redis import Redis
import socket
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
@app.route('/')
defhello():
count = redis.incr('hits')
host_name = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
return'<h1>Hello World!</h1>' \
'I have been seen %s times<br>' \
'HostName = %s<br>' \
'IP = %s<br>' \
'Try refreshing the page.'%(count, host_name, host_ip)
if __name__ =="__main__":
app.run(host="0.0.0.0", port=8000, debug=True)
Add the application dependencies:
./requirements.txt
flask
redis
Describe the build steps in a Dockerfile:
./Dockerfile
FROM python:3.4-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
Describe the application stack in a docker-compose.yml file including the desired hostname for the frontend service and internal container port to expose:
Describe the application stack in a docker-compose.yml file including the desired hostname for the frontend service and internal container port to expose: