Skip to content

add docker-compose.yml #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.linting.pylintEnabled": false
}
28 changes: 0 additions & 28 deletions Dockerfile

This file was deleted.

12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
This repository contains files necessary for building a Docker image of
Nginx + Gunicorn + Flask.

### changes:
+ using official python image[https://hub.docker.com/r/_/python/]
+ run by docker-compose
+ mount codes by -v
+ mount 3 .conf files by -v for nginx gunicorn supervisord


### Base Docker Image

* [ubuntu:12.04](https://registry.hub.docker.com/_/ubuntu/)
* python


### Installation
Expand All @@ -22,8 +28,8 @@ docker pull danriti/nginx-gunicorn-flask

### Usage

```bash
docker run -d -p 80:80 danriti/nginx-gunicorn-flask
```run py docker-compose

```

After few seconds, open `http://<host>` to see the Flask app.
17 changes: 17 additions & 0 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
""" hello.py """

from flask import Flask, jsonify, render_template,url_for

app = Flask(__name__)

@app.route('/')
@app.route('/<name>')
def hello(name=None):
# return jsonify({
# 'hello': 'world'
# })
bg_img = url_for('static',filename='bg.jpg')
return render_template('hello.html', name=name,bg_img=bg_img)

if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)
14 changes: 0 additions & 14 deletions app/hello.py

This file was deleted.

1 change: 0 additions & 1 deletion app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ MarkupSafe==0.23
Werkzeug==0.10.4
argparse==1.2.1
itsdangerous==0.24
wsgiref==0.1.2
Binary file added app/static/bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added app/static/style.css
Empty file.
10 changes: 10 additions & 0 deletions app/templates/hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<title>Hello from Flask</title>
{% if name %}
<h1>Hello {{ name }}!</h1>
{% else %}
<h1>Hello, World 233!</h1>
{% endif %}
<!-- <img src="/static/bg.jpg"/> -->
<img src= "{{ bg_img }}"/>

18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3.3"

services:
api:
#restart: always
stdin_open: true
tty: true
build: .
image: nginx-gunicorn-flask:latest
volumes:
- ./app:/deploy/app
- ./nginx_flask.conf:/etc/nginx/sites-available/nginx_flask.conf
- ./gunicorn.conf:/etc/supervisor/conf.d/gunicorn.conf
- ./supervisord.conf:/etc/supervisor/conf.d/supervisord.conf
ports:
- "80:80"
#command: '/bin/bash'
command: '/usr/bin/supervisord'
35 changes: 35 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# nginx-gunicorn-flask with python3

FROM python
LABEL author="xuqinghan"
LABEL purpose = ''


RUN apt update
RUN apt install -y nginx supervisor
RUN pip3 install gunicorn
RUN pip3 install setuptools

ENV PYTHONIOENCODING=utf-8

# Build folder
RUN mkdir -p /deploy/app
WORKDIR /deploy/app
#only copy requirements.txt. othors will be mounted by -v
COPY app/requirements.txt /deploy/app/requirements.txt
RUN pip3 install -r /deploy/app/requirements.txt

# Setup nginx
RUN rm /etc/nginx/sites-enabled/default
COPY nginx_flask.conf /etc/nginx/sites-available/
RUN ln -s /etc/nginx/sites-available/nginx_flask.conf /etc/nginx/sites-enabled/nginx_flask.conf
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

# Setup supervisord
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY gunicorn.conf /etc/supervisor/conf.d/gunicorn.conf

# run sh. Start processes in docker-compose.yml
#CMD ["/usr/bin/supervisord"]
CMD ["/bin/bash"]
2 changes: 1 addition & 1 deletion gunicorn.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[program:gunicorn]
command=/usr/bin/gunicorn hello:app -b localhost:5000
command=gunicorn --workers=3 app:app -b localhost:5000
directory=/deploy/app
4 changes: 4 additions & 0 deletions flask.conf → nginx_flask.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ server {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ^~ /static/ {
root /deploy/app/;
}
}