Skip to content

Commit e55d034

Browse files
Chapter 17: Docker support (17d)
1 parent 2a692e0 commit e55d034

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
@@ -89,11 +89,25 @@ def init_app(cls, app):
8989
app.logger.addHandler(file_handler)
9090

9191

92+
class DockerConfig(ProductionConfig):
93+
@classmethod
94+
def init_app(cls, app):
95+
ProductionConfig.init_app(app)
96+
97+
# log to stderr
98+
import logging
99+
from logging import StreamHandler
100+
file_handler = StreamHandler()
101+
file_handler.setLevel(logging.INFO)
102+
app.logger.addHandler(file_handler)
103+
104+
92105
config = {
93106
'development': DevelopmentConfig,
94107
'testing': TestingConfig,
95108
'production': ProductionConfig,
96109
'heroku': HerokuConfig,
110+
'docker': DockerConfig,
97111

98112
'default': DevelopmentConfig
99113
}

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)