├── Dockerfile ├── README.md ├── app.py ├── docker-compose.yml └── requirements.txt /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:2.7 2 | ADD . /code 3 | WORKDIR /code 4 | RUN pip install -r requirements.txt 5 | CMD python app.py 6 | 7 | # docker build -t web . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting started with docker-compose, using python/flask & redis 2 | 3 | Compose is a tool for defining and running multi-container Docker applications. You use a Compose file to configure your application’s services. Then using a single command, you create and start all the services. 4 | 5 | In this repo, there is a basic python flask web app in `app.py`, a Dockerfile for the specs of the container for that app (which is based off a python image), a requirements file for Docker installation additional requirements for the app (flask, redis), and a docker-compose file for the specification of the composed containers which includes the flask and redis containers. I created this in conjunction with reading this docker-compose tutorial, so you can use it to get more information on what these files do, https://docs.docker.com/compose/gettingstarted/ 6 | 7 | To get the app running in one container with redis in another, try these steps: 8 | 9 | 1. Create the files locally. See if you can tell what each one does. Check the above link to learn more. 10 | 11 | 1. Run `docker-compose build' to build the containers specified in the docker-compose file. 12 | 13 | 1. Run `docker-compose up` to start the containers (add -d to run them in the background. Then run `docker-compose stop` when done.) 14 | 15 | 1. Browse to http://localhost:5000 to see the response from the web app. 16 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from redis import Redis 3 | 4 | app = Flask(__name__) 5 | redis = Redis(host='redis', port=6379) 6 | 7 | @app.route('/') 8 | def hello(): 9 | redis.incr('hits') 10 | return 'Hello World! I have been seen %s times.' % redis.get('hits') 11 | 12 | if __name__ == "__main__": 13 | app.run(host="0.0.0.0", debug=True) -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | web: 4 | build: . 5 | ports: 6 | - "5000:5000" 7 | volumes: 8 | - .:/code 9 | depends_on: 10 | - redis 11 | redis: 12 | image: redis -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | redis --------------------------------------------------------------------------------