Skip to content

Commit c73cb49

Browse files
Chapter 17: Docker support (17d)
1 parent 12f4446 commit c73cb49

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM python:3.6-alpine
2+
3+
ENV FLASK_APP flasky.py
4+
ENV FLASK_CONFIG production
5+
6+
RUN adduser -D flasky
7+
USER flasky
8+
9+
WORKDIR /home/flasky
10+
11+
COPY requirements requirements
12+
RUN python -m venv venv
13+
RUN venv/bin/pip install -r requirements/docker.txt
14+
15+
COPY app app
16+
COPY migrations migrations
17+
COPY flasky.py config.py boot.sh ./
18+
19+
# run-time configuration
20+
EXPOSE 5000
21+
ENTRYPOINT ["./boot.sh"]

boot.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
source venv/bin/activate
3+
flask deploy
4+
exec gunicorn -b :5000 --access-logfile - --error-logfile - flasky:app

config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,25 @@ def init_app(cls, app):
8686
app.logger.addHandler(file_handler)
8787

8888

89+
class DockerConfig(ProductionConfig):
90+
@classmethod
91+
def init_app(cls, app):
92+
ProductionConfig.init_app(app)
93+
94+
# log to stderr
95+
import logging
96+
from logging import StreamHandler
97+
file_handler = StreamHandler()
98+
file_handler.setLevel(logging.INFO)
99+
app.logger.addHandler(file_handler)
100+
101+
89102
config = {
90103
'development': DevelopmentConfig,
91104
'testing': TestingConfig,
92105
'production': ProductionConfig,
93106
'heroku': HerokuConfig,
107+
'docker': DockerConfig,
94108

95109
'default': DevelopmentConfig
96110
}

requirements/docker.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-r common.txt
2+
gunicorn==19.7.1

0 commit comments

Comments
 (0)