Skip to content

Commit

Permalink
Chapter 17: Docker support (17d)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Jun 9, 2019
1 parent 599379c commit d8b97e0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.6-alpine

ENV FLASK_APP flasky.py
ENV FLASK_CONFIG production

RUN adduser -D flasky
USER flasky

WORKDIR /home/flasky

COPY requirements requirements
RUN python -m venv venv
RUN venv/bin/pip install -r requirements/docker.txt

COPY app app
COPY migrations migrations
COPY flasky.py config.py boot.sh ./

# run-time configuration
EXPOSE 5000
ENTRYPOINT ["./boot.sh"]
4 changes: 4 additions & 0 deletions boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
source venv/bin/activate
flask deploy
exec gunicorn -b :5000 --access-logfile - --error-logfile - flasky:app
14 changes: 14 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,25 @@ def init_app(cls, app):
app.logger.addHandler(file_handler)


class DockerConfig(ProductionConfig):
@classmethod
def init_app(cls, app):
ProductionConfig.init_app(app)

# log to stderr
import logging
from logging import StreamHandler
file_handler = StreamHandler()
file_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)


config = {
'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig,
'heroku': HerokuConfig,
'docker': DockerConfig,

'default': DevelopmentConfig
}
2 changes: 2 additions & 0 deletions requirements/docker.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-r common.txt
gunicorn==19.7.1

0 comments on commit d8b97e0

Please sign in to comment.