Skip to content

Commit v0.1

kwmccabe edited this page Apr 17, 2018 · 17 revisions

v0.1 - Hello FlaskApp: docker-compose.yml, web/Dockerfile, web/requirements.txt, web/flaskapp.py


Files changed (4)

File docker-compose.yml ADDED

  • This is a minimal Docker Compose file with the default name, just to get running.
  • version : Be careful when researching Compose issues to note the version. Many version 2 solutions will not work under version 3.
  • services : Each service is a different Docker container
  • web : We'll start with a single service called web
  • build : The location of this service's Dockerfile - in this case, inside the project's web directory.
  • ports : Opens a public port 5000 and connects it to the container port 8000
  • command : Launch the application flaskapp:app and tell gunicorn to make it available on port 8000
+version: "3"
+services:
+    web:
+        build: ./web
+        ports:
+            - "5000:8000"
+        command: /usr/local/bin/gunicorn -b :8000 flaskapp:app

File web/Dockerfile ADDED

  • A minimal Docker file.
+# base container image
+FROM python:3.6.1-alpine
+
+# setup working directory within container
+RUN mkdir -p /web
+WORKDIR /web
+
+# copy code from current directory into working directory
+COPY . /web
+
+# setup python environment, import required modules
+RUN pip install --upgrade pip
+RUN pip install --no-cache-dir -r requirements.txt

File web/flaskapp.py ADDED

  • A minimal Flask application.
  • Create the application app - referenced by the gunicorn command in docker-compose.yml
  • Define the default route / - returns the string Hello FlaskApp
+from flask import Flask
+app = Flask(__name__)
+
+@app.route('/')
+def hello_flaskapp():
+    return 'Hello FlaskApp'

File web/requirements.txt ADDED

  • Only two packages are required at this stage. During the install, pip will fetch the latest versions.
+Flask
+gunicorn

About | Commit-v0.1 | Commit-v0.2

Clone this wiki locally