Skip to content

Commit 2d9cf57

Browse files
committed
basic docerization is working
1 parent 39b8b29 commit 2d9cf57

File tree

6 files changed

+32
-16
lines changed

6 files changed

+32
-16
lines changed

api/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

api/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ RUN pip install -r requirements.txt
2121
COPY . .
2222

2323
# Finally, run the app with Gunicorn command
24-
CMD [ "gunicorn", "-b", "0.0.0.0:5000", "wsgi:app" ]
24+
# CMD [ "gunicorn", "-b", "0.0.0.0:5000", "wsgi:app" ]
25+
CMD [ "gunicorn", "-c", "gunicorn.conf.py", "wsgi:app" ]
26+
# CMD [ "python", "app.py" ]

api/app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ def put(self, id):
9292

9393

9494
if __name__ == '__main__':
95-
app.run(debug=True)
95+
print(" ** Starting flask app...")
96+
app.run(debug=True)
97+
print(" ** Started flask app!")
98+

api/gunicorn.conf.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# import multiprocessing
2+
3+
pidfile = 'flask_app.pid'
4+
workers = 2
5+
# workers = multiprocessing.cpu_count() * 2 + 1
6+
bind = '0.0.0.0:5000'
7+
accesslog = './logs/access.log'
8+
errorlog = './logs/error.log'
9+
# user = 'ubuntu'
10+
# group = 'ubuntu'

docker-compose.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@ version: '3.7'
22

33
services:
44

5-
api_end:
5+
flask-api:
66
shm_size: '1000000000'
7+
image: api_img
8+
container_name: ai_api
79
build:
810
context: api
911
tty: true
1012
volumes:
11-
- '~/docker_app:/app'
13+
- ~/docker_app/api:/app/logs
14+
expose:
15+
- 5000
1216

1317
nginx:
1418
build: nginx
19+
image: nginx_img
20+
container_name: ai_nginx
1521
tty: true
16-
links:
17-
- api_end
1822
ports:
19-
- '8084:80'
23+
- '80:80'
24+
volumes:
25+
- ~/docker_app/nginx:/var/log/nginx/

nginx/nginx.conf

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
# events { worker_connections 1024; }
2-
31
server {
42
listen 80;
5-
server_name http://api_end:5000;
3+
server_name localhost;
4+
65
location / {
7-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
8-
proxy_set_header X-Real-IP $remote_addr;
9-
proxy_redirect off;
10-
proxy_buffers 8 24k;
11-
proxy_buffer_size 4k;
12-
proxy_pass http://localhost;
6+
proxy_pass http://flask-api:5000/;
137
proxy_set_header Host $host;
148
}
159
}

0 commit comments

Comments
 (0)