Giter VIP home page Giter VIP logo

tiangolo / uwsgi-nginx-flask-docker Goto Github PK

View Code? Open in Web Editor NEW
3.0K 60.0 604.0 329 KB

Docker image with uWSGI and Nginx for Flask applications in Python running in a single container.

Home Page: https://hub.docker.com/r/tiangolo/uwsgi-nginx-flask/

License: Apache License 2.0

Python 73.27% HTML 0.69% Shell 7.78% Dockerfile 18.27%
uwsgi-nginx flask-application docker-image python-flask docker-container flask dockerfile uwsgi nginx nginx-server

uwsgi-nginx-flask-docker's Introduction

Hey! I'm @tiangolo (Sebastián Ramírez) 👋

I'm a software developer from Colombia. 🇨🇴

I currently live in Berlin, Germany. 🇩🇪

I have been building APIs and tools for Machine Learning and data systems, in Latin America, the Middle East, and now Europe, with different teams and organizations. 🌎

I created FastAPI, Typer and a bunch of other open source tools. 🚀

I like to build things with Deep Learning/Machine Learning, distributed systems, SQL and NoSQL databases, Docker, Python, TypeScript (and JavaScript), modern backend APIs, and modern frontend frameworks. 🤖

I'm currently dedicating a high percentage of my time to FastAPI, Typer, and my other open source projects. At the same time, I'm also helping a limited number of teams and organizations as an external consultant. If you would like to have my help with your team and product, feel free to contact me. 🤓

If my open source projects are useful for your product/company you can also sponsor my work on them. ☕

You can find me on:

uwsgi-nginx-flask-docker's People

Contributors

alejsdev avatar arthurarslanaliev avatar boyu1997 avatar cclauss avatar dependabot[bot] avatar desaintmartin avatar ericboucher avatar mariacamilagl avatar pjrule avatar reka169 avatar ronlut avatar tiangolo avatar timgates42 avatar vsund avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uwsgi-nginx-flask-docker's Issues

Unable to change nginx.conf in the image

This may seem a little strange, but I am not able to change nginx.conf file inside /etc/nginx/conf.d/nginx.conf

Here is what I did:

Method1: Change in Dockerfile

My Dockerfile looks like this:

FROM tiangolo/uwsgi-nginx-flask:flask
COPY ./app /app
COPY ./changes/nginx.conf /etc/nginx/conf.d/nginx.conf
COPY ./changes/nginx.conf /app/

./changes/nginx.conf looks like this:

server {
    location /app1/ {
        try_files $uri @app;
    }
    location @app {
        include uwsgi_params;
        uwsgi_pass unix:///tmp/uwsgi.sock;
    }
    location /static {
        alias /app/static;
    }
}

Note the change in location in above server block from location / to location /app1/

After the image is built and I run the docker container, I exec into the running container
sudo docker exec -ti CONTAINER_ID /bin/bash

cat /app/nginx.conf shows presence of updated nginx.conf file (location changes from / to /app1/

BUT cat /etc/nginx/conf.d/nginx.conf still shows the old conf file (location is still /)
I thought maybe the second COPY line is not getting executed successfully and docker isn't throwing error on console (sudo?). So, I changed the conf file manually and did a docker commit - the second approach mentioned below.

Method2: Docker commit

After the docker container was up and running, I used exec to login into the container using
[vagrant@localhost]$ sudo docker exec -ti CONTAINER_ID /bin/bash

[root@CONTAINER_ID]# vi /etc/nginx/conf.d/nginx.conf
Changing the file to reflect below:

server {
    location /app1/ {
        try_files $uri @app;
    }
    location @app {
        include uwsgi_params;
        uwsgi_pass unix:///tmp/uwsgi.sock;
    }
    location /static {
        alias /app/static;
    }
}

Saved the file wq! and exit the container.
After that I did sudo docker commit CONTAINER_ID my_new_image

Starting a new container and re-logging into container running on my_new_image still gives below nginx.conf file inside /etc/nginx/conf.d/nginx.conf:

server {
    location / {
        try_files $uri @app;
    }
    location @app {
        include uwsgi_params;
        uwsgi_pass unix:///tmp/uwsgi.sock;
    }
    location /static {
        alias /app/static;
    }
}

I can tell that the my_new_image has some changes because it is larger in size than tiangolo/uwsgi-nginx-flask-docker because I had installed vim to edit the file. But somehow file changes are not persisting inside /etc/nginx/conf.d/nginx.conf.

Am I doing something wrong or is it some bug?

Changing `WORKDIR` causes uWSGI to not find app

I have a Dockerfile with the following contents:

FROM tiangolo/uwsgi-nginx-flask:python3.6
COPY app /app
COPY foo /tmp/foo
WORKDIR /tmp/foo
RUN some other commands
# More RUN commands

When I build this image I get the following errors:

ModuleNotFoundError: No module named 'main'
unable to load app 0 (mountpoint='') (callable not found or import error)

Why does the WORKDIR in my Dockerfile affect the functionality of the base image?

My apologies if this is obvious or expected behaviour; I don't have much Docker experience.

Invalid checksum for python3.6

Looks like the checksum is invalid for one of the layers in python3.6 causing pull failure:

➜  ~ docker pull tiangolo/uwsgi-nginx:python3.6
python3.6: Pulling from tiangolo/uwsgi-nginx
723254a2c089: Pull complete
abe15a44e12f: Pull complete
409a28e3cc3d: Pull complete
503166935590: Pull complete
0f46f97746e4: Verifying Checksum
fe27feb3d509: Download complete
5efd1be29fdb: Download complete
1c7f21b2c7a5: Download complete
19d6f0b88217: Download complete
9bc015449d3b: Download complete
bc6664ce3000: Download complete
5637fc6942bc: Download complete
3e8e08378b8c: Download complete
9ee4941c6912: Download complete
68dc3e6ae1ee: Download complete
c99e37b352fe: Download complete
951c675c83e3: Download complete
d70540e3752a: Download complete
7e38e9f9b2d7: Download complete
a9852b3eea18: Download complete
97deda0086e7: Download complete
filesystem layer verification failed for digest sha256:0f46f97746e4df5959e8c821ca69fdd6c0bedd611c1e0ab3b6970f7202b9bb10
➜  ~

I was able to successfully pull from python3.6-alpine3.7 as well as python3.5.

Cannot install module lxml.

at alpine cannot install module lxml like : pip install lxml,
but i find packages py3-lxml, i can install module like : apk add py3-lxml,
it used for my alpine linux or my dockerfile(form alpine:3.7)

`FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7
#FROM alpine:3.7

RUN apk update add python3
RUN apk add py3-lxml
RUN pip3 install pip==10.0.0
RUN pip3 freeze
`
if i use base from alpine:3.7,lxml be install,
use you tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7,lxml be not install.

some bug?or?

Add prefix to flask application URLs

I am wondering if you would consider allow users of this docker image to be able to set their own prefix of the flask application. For example, I would like to do something like this:

  • location \ served directly from a directory, not just index.html
  • location \api served by flask app

Or better yet, allow users to use their own nginx.conf. We could do this by checking if a nginx.conf file already exists before generating one in entrypoint.sh.

Thanks!

add pip to container

how to add pip to container? I mean sure, can do con command but doesn't it change the behaviour?

Passing arguments to main.py

I'm trying to understand how the main.py file in the /app folder is called, and how I can send arguments to it? I have a project where I would like to start the main.py file by passing it an argument when I create a container.

ggc breaks nginx?

I am trying to use tiangolo/uwsgi-nginx-flask:python3.6 as a base image so that I can build a Docker for my Flask WebApp. I have a Kerberos and MS SQL Server dependency. I have been racking my brain trying to get this to work for awhile. I think the problem is with gcc. I couldn't figure out what was wrong for a while and finally just started off adding one program at a time. I didn't get too far till I got the error below.

*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.6.4 (default, Dec 21 2017, 01:29:34)  [GCC 6.3.0 20170516]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x5558e0f37f70
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 1237056 bytes (1208 KB) for 16 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x5558e0f37f70 pid: 9 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 9)
spawned uWSGI worker 1 (pid: 11, cores: 1)
spawned uWSGI worker 2 (pid: 12, cores: 1)
2018-04-06 21:21:04,343 INFO spawned: 'nginx' with pid 13
2018-04-06 21:21:04,343 INFO success: uwsgi entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018/04/06 21:21:04 [emerg] 13#13: open() "/etc/nginx/conf.d/default.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:31
nginx: [emerg] open() "/etc/nginx/conf.d/default.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:31
2018-04-06 21:21:04,361 INFO exited: nginx (exit status 1; not expected)
2018-04-06 21:21:06,366 INFO spawned: 'nginx' with pid 14
2018/04/06 21:21:06 [emerg] 14#14: open() "/etc/nginx/conf.d/default.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:31
nginx: [emerg] open() "/etc/nginx/conf.d/default.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:31
2018-04-06 21:21:06,384 INFO exited: nginx (exit status 1; not expected)
2018-04-06 21:21:09,391 INFO spawned: 'nginx' with pid 15
2018/04/06 21:21:09 [emerg] 15#15: open() "/etc/nginx/conf.d/default.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:31
nginx: [emerg] open() "/etc/nginx/conf.d/default.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:31
2018-04-06 21:21:09,409 INFO exited: nginx (exit status 1; not expected)
2018-04-06 21:21:10,409 INFO gave up: nginx entered FATAL state, too many start retries too `quickly`

My Dockerfile that made this looks like:

FROM tiangolo/uwsgi-nginx-flask:python3.6

RUN echo "deb http://ftp.us.debian.org/debian unstable main contrib non-free" > /etc/apt/sources.list.d/unstable.list
RUN cat /etc/*-release

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get -qq update && apt-get -y install libopendbx1-mssql curl apt-transport-https

RUN apt-get -y install gcc

###############################################################
# Copy over Kerberos config files
###############################################################
COPY ./krb5.conf /etc/krb5.conf
COPY ./common-session /etc/pam.d/common-session
COPY ./webapp.keytab /etc/krb5.keytab

COPY ./app /app

COPY failed: stat /var/lib/docker/tmp/docker-builder192707116/start.sh: no such file or directory

ubuntu 18.04 desktop, docker

Docker version 17.12.1-ce, build 7390fc

When I run command: sudo docker build -t myimage . I get some errors follows:

hengaini2055@ubuntu:~/docker_flask$ sudo docker build -t myimage .
[sudo] hengaini2055 的密码: ********

Sending build context to Docker daemon  5.632kB
Step 1/17 : FROM tiangolo/uwsgi-nginx:python3.6
 ---> dadfb1bf0a6c
Step 2/17 : RUN pip install flask
 ---> Using cache
 ---> 2fa96d341119
Step 3/17 : ENV NGINX_MAX_UPLOAD 0
 ---> Using cache
 ---> 2e7d880ac1cd
Step 4/17 : ENV LISTEN_PORT 80
 ---> Using cache
 ---> bcd7a9ac98af
Step 5/17 : ENV UWSGI_INI /app/uwsgi.ini
 ---> Using cache
 ---> 0fb2e3ec14d4
Step 6/17 : ENV STATIC_URL /static
 ---> Using cache
 ---> 258e335c1df0
Step 7/17 : ENV STATIC_PATH /app/static
 ---> Using cache
 ---> 15aeda17eec3
Step 8/17 : ENV STATIC_INDEX 0
 ---> Using cache
 ---> 8428457afc49
Step 9/17 : COPY ./app /app
 ---> 9a9a7da78738
Step 10/17 : WORKDIR /app
Removing intermediate container b5e2b9573adb
 ---> 541731aa343f
Step 11/17 : ENV PYTHONPATH=/app
 ---> Running in 21f7a6760678
Removing intermediate container 21f7a6760678
 ---> c04c0208964f
Step 12/17 : COPY start.sh /start.sh
COPY failed: stat /var/lib/docker/tmp/docker-builder898591638/start.sh: no such file or directory

Python packages still not available to app after pip install

I have additional requirements I need to install for my app. Here's my Dockerfile:

FROM tiangolo/uwsgi-nginx-flask:python3.6

ENV STATIC_INDEX 1

COPY requirements.txt /app/
RUN pip install -r /app/requirements.txt

COPY . /app

Even after rebuilding, the app still can't import my packages. When I bring up the docker container, I get this in the output:

Traceback (most recent call last):
  File "./main.py", line 4, in <module>
    from flask_cors import CORS

The build step does show it installing the package.

Building web
Step 1/5 : FROM tiangolo/uwsgi-nginx-flask:python3.6
 ---> 590e17342131
Step 2/5 : ENV STATIC_INDEX 1
 ---> Using cache
 ---> be704d970645
Step 3/5 : COPY requirements.txt /app/
 ---> Using cache
 ---> 9a2d06e8c82e
Step 4/5 : RUN pip install -r /app/requirements.txt
 ---> Running in 85413afc84ee
Collecting certifi==2017.7.27.1 (from -r /app/requirements.txt (line 1))
  Downloading certifi-2017.7.27.1-py2.py3-none-any.whl (349kB)
Collecting chardet==3.0.4 (from -r /app/requirements.txt (line 2))
  Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB)
Requirement already satisfied: click==6.7 in /usr/local/lib/python3.6/site-packages (from -r /app/requirements.txt (line 3))
Requirement already satisfied: Flask==0.12.2 in /usr/local/lib/python3.6/site-packages (from -r /app/requirements.txt (line 4))
Collecting Flask-Cors==3.0.3 (from -r /app/requirements.txt (line 5))
  Downloading Flask_Cors-3.0.3-py2.py3-none-any.whl
Collecting idna==2.6 (from -r /app/requirements.txt (line 6))
  Downloading idna-2.6-py2.py3-none-any.whl (56kB)
Requirement already satisfied: itsdangerous==0.24 in /usr/local/lib/python3.6/site-packages (from -r /app/requirements.txt (line 7))
Requirement already satisfied: Jinja2==2.9.6 in /usr/local/lib/python3.6/site-packages (from -r /app/requirements.txt (line 8))
Requirement already satisfied: MarkupSafe==1.0 in /usr/local/lib/python3.6/site-packages (from -r /app/requirements.txt (line 9))
Collecting requests==2.18.4 (from -r /app/requirements.txt (line 10))
  Downloading requests-2.18.4-py2.py3-none-any.whl (88kB)
Collecting six==1.11.0 (from -r /app/requirements.txt (line 11))
  Downloading six-1.11.0-py2.py3-none-any.whl
Collecting urllib3==1.22 (from -r /app/requirements.txt (line 12))
  Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
Requirement already satisfied: Werkzeug==0.12.2 in /usr/local/lib/python3.6/site-packages (from -r /app/requirements.txt (line 13))
Installing collected packages: certifi, chardet, six, Flask-Cors, idna, urllib3, requests
Successfully installed Flask-Cors-3.0.3 certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 six-1.11.0 urllib3-1.22
 ---> 0437821ea780
Removing intermediate container 85413afc84ee
Step 5/5 : COPY . /app
 ---> aed7dfd1c4a8
Removing intermediate container debc2010ff97
Successfully built aed7dfd1c4a8
Successfully tagged app_web:latest

Can anyone see what I'm doing wrong here? Thank you!

Using SSL Certificates

Hi Tiangolo! Thank you for this.

I'm having a real hard time installing SSL certificates for this docker image.

Is there any additional changes I should implement?

This is how I have modified nginx.conf:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
    ssl_certificate /etc/ssl/www.messiac.com.crt;
    ssl_certificate_key /etc/ssl/www.messiac.com.key;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
    ssl_dhparam /path/to/dhparam.pem;

    # intermediate configuration. tweak to your needs.
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES1$
    ssl_prefer_server_ciphers on;

    # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
    add_header Strict-Transport-Security max-age=15768000;

    # OCSP Stapling ---
    # fetch OCSP records from URL in ssl_certificate and cache them
    ssl_stapling on;
    ssl_stapling_verify on;

# certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
    ssl_certificate /etc/ssl/www.messiac.com.crt;
    ssl_certificate_key /etc/ssl/www.messiac.com.key;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
    ssl_dhparam /path/to/dhparam.pem;

    # intermediate configuration. tweak to your needs.
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES1$
    ssl_prefer_server_ciphers on;

    # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
    add_header Strict-Transport-Security max-age=15768000;

    # OCSP Stapling ---
    # fetch OCSP records from URL in ssl_certificate and cache them
    ssl_stapling on;
    ssl_stapling_verify on;

    ## verify chain of trust of OCSP response using Root CA and Intermediate certs
    ssl_trusted_certificate /etc/ssl/www.messiac.com.crt;

    resolver <IP DNS resolver>;

    ....
}

daemon off;

No support for HTTPs

I'm trying to figure this out now. I would prefer not to check the keys into my repo or bake them into the image.

As it stands, it looks like I'll have to overwrite entrypoint.sh so that it writes a different nginx.conf that points to a cert and a key in a volume that runner of the container can create. I'm pretty new to docker though... any recommendations?

Logging problems

Hi tiangolo,

I am having problems logging messages when I used the uwsgi-nginx-flask image. The application works. I am only having issues with the logging. On the other hand, If I run the app in standalone, everything, including logging, works as expected.

I tried to look for info on how to configure the logging mechanism when using uwsgi-nginx-flask, but I was not able to find anything.

Let me explain the scenario.

I am using uwsgi-nginx-flask:python3.6 to run a flask app.

My uwsgi.ini is

[uwsgi]
module = iedapp.app
callable = app
logger = python

The app is using resources for handling request.

....
app = Flask(__name__, static_folder=None)
app.config.from_object(config)
api = Api(app, prefix='/api', base_path='/api', api_version='1.0')
api.add_resource(IedOnline, '/online/<string:ied_key>/<string:layout>')
....

And in the resource, I have something like

....
logger = logging.getLogger('test')

class IedOnline(Resource):
    def post(self, ied_key, layout):
         print("Hello!!!")
         current_app.logger.error("Hello again!!!!")
         logger.error("Hello again and again")
....

What happens to me is that both the print and logging messages in the resource function get lost. I am not able to find them either in the docker logs not if I exec into the docker image and look for entries in all the *.log files in the image.

Could you provide guidance on what I should be going wrong?

NGINX don´t start

Hi, sorry for my noob question, but i´m beggining on docker.

Is It there something that disable nginx when I start a container with debug directives ? I started the container using this command line:

docker run -d --name mycontainer -p 80:80 -v $(pwd)/app:/app -e FLASK_APP=main.py -e FLASK_DEBUG=1 myimage flask run --host=0.0.0.0 --port=80

After do some packages instalations on container I commited to a new image. After this, when I start a new container using this new image, it always run in debug mode.

net::ERR_INCOMPLETE_CHUNKED_ENCODING

I have a jquery front end that is trying to send images to an app inside the uwsgi-nginx-flask-docker container.

The javascript console is saying this:
jquery.min.js:4 POST http://localhost:8000/predict/ net::ERR_INCOMPLETE_CHUNKED_ENCODING

If I use the same app with only gunicorn it works ok, so I'm suspecting this is related to nginix configuration inside the container?

more Dockerfile
FROM tiangolo/uwsgi-nginx-flask:python3.6

COPY ./app /app

RUN pip install -r requirements.txt

On the client side I'm using this plugin to submit the form using ajax http://malsup.com/jquery/form/

Issues when using Docker image for libarchive

When I try to install dependencies I get this error:

Running setup.py install for libarchive: started
    Running setup.py install for libarchive: finished with status 'error'
    Complete output from command /usr/local/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-2wn34352/libarchive/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-ni2x9d0m-record/install-record.txt --single-version-externally-managed --compile:
    running install
    Verifying that the library is accessible.
    Library can not be loaded: libarchive.so: cannot open shared object file: No such file or directory
    error: libarchive.so: cannot open shared object file: No such file or directory

    ----------------------------------------
Command "/usr/local/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-2wn34352/libarchive/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-ni2x9d0m-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-2wn34352/libarchive/
The command '/bin/sh -c pip install --requirement /tmp/requirements.txt' returned a non-zero code: 1

My requirements file looks like this

aniso8601==1.2.1
appdirs==1.4.3
appnope==0.1.0
bleach==2.0.0
boto==2.46.1
bz2file==0.98
click==6.7
Cython==0.25.2
decorator==4.0.11
editdistance==0.3.1
entrypoints==0.2.2
fasttext==0.8.3
Flask==0.12.2
Flask-RESTful==0.3.6
future==0.16.0
gensim==2.0.0
html5lib==0.999999999
ipykernel==4.6.1
ipython==6.0.0
ipython-genutils==0.2.0
ipywidgets==6.0.0
itsdangerous==0.24
jedi==0.10.2
Jinja2==2.9.6
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.0.1
jupyter-console==5.1.0
jupyter-contrib-core==0.3.1
jupyter-core==4.3.0
jupyter-highlight-selected-word==0.0.11
jupyter-latex-envs==1.3.8.4
jupyter-nbextensions-configurator==0.2.4
libarchive==0.4.3
MarkupSafe==1.0
mistune==0.7.4
nbconvert==5.1.1
nbformat==4.3.0
nose==1.3.7
notebook==5.0.0
numpy==1.12.1
packaging==16.8
pandocfilters==1.4.1
pexpect==4.2.1
pickleshare==0.7.4
prompt-toolkit==1.0.14
protobuf==3.2.0
psutil==5.2.2
ptyprocess==0.5.1
pyemd==0.4.3
Pygments==2.2.0
pyparsing==2.2.0
python-dateutil==2.6.0
pytz==2017.2
PyYAML==3.12
pyzmq==16.0.2
qtconsole==4.3.0
requests==2.13.0
scikit-learn==0.18.1
scipy==0.19.0
simplegeneric==0.8.1
six==1.10.0
sklearn==0.0
smart-open==1.5.2
tensorflow==1.1.0
terminado==0.6
testpath==0.3
tornado==4.5.1
tqdm==4.11.2
traitlets==4.3.2
wcwidth==0.1.7
webencodings==0.5.1
Werkzeug==0.12.1
widgetsnbextension==2.0.0

Docker file:

FROM tiangolo/uwsgi-nginx:python3.5

MAINTAINER Sebastian Ramirez <[email protected]>

RUN pip install --upgrade pip
RUN pip install cython
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt

# Add app configuration to Nginx
COPY nginx.conf /etc/nginx/conf.d/

# Copy sample app
COPY ./app /app

Adding own domain and SSL certificates

Hi,

first of all thank you very much for this image. It has made everything so much easiert. I don't know if that belongs here but could you give me a short description of how I can add SSL certificates and how I can use my own domain? Currently I just access the Flask app by opening the IP adress of my Ubuntu server.

Thanks a lot for your time.

Add ELK Elasticsearch to this template

Struggeling to find a good setup with ELK to monitor a flask api backend. I want to log all api requests and maybe certain things within the flask app. Would be awesome if this could be included here!

Unable to run in Openshift

Container can not run in openshift because its trying to write to /etc/nginx/. Containers in Openshift (by default) are not running as root nor they can't get root access.

prestart.sh not run in Ubuntu 16.04

Hi,

I have encountered a problem regarding restart.sh. Not sure if it is because of my error or not.

I have a Ubuntu 16.04 server. If I execute docker run tiangolo/uwsgi-nginx-flask:python3.6 on it, I get the following output:

/usr/lib/python2.7/dist-packages/supervisor/options.py:296: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
  'Supervisord is running as root and it is searching '
2018-01-05 21:23:59,700 CRIT Supervisor running as root (no user in config file)
2018-01-05 21:23:59,700 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
2018-01-05 21:23:59,721 INFO RPC interface 'supervisor' initialized
2018-01-05 21:23:59,721 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2018-01-05 21:23:59,722 INFO supervisord started with pid 1
2018-01-05 21:24:00,725 INFO spawned: 'nginx' with pid 9
2018-01-05 21:24:00,727 INFO spawned: 'uwsgi' with pid 10
[uWSGI] getting INI configuration from /app/uwsgi.ini
[uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini
*** Starting uWSGI 2.0.15 (64bit) on [Fri Jan  5 21:24:00 2018] ***
compiled with version: 4.9.2 on 10 August 2017 16:32:21
os: Linux-4.4.0-22-generic #40-Ubuntu SMP Thu May 12 22:03:46 UTC 2016
nodename: cb776ddb69b0
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /app
detected binary path: /usr/local/bin/uwsgi
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.6.2 (default, Jul 24 2017, 19:47:39)  [GCC 4.9.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x238af00
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 1237056 bytes (1208 KB) for 16 cores
*** Operational MODE: preforking ***
2018-01-05 21:24:01,792 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-01-05 21:24:01,792 INFO success: uwsgi entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x238af00 pid: 10 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 10)
spawned uWSGI worker 1 (pid: 13, cores: 1)
spawned uWSGI worker 2 (pid: 14, cores: 1)

However, on a Mac running macOS 10.13.2, executing the same command, I get the following output

Checking for script in /app/prestart.sh
Running script /app/prestart.sh
Running inside /app/prestart.sh, you could add migrations to this file, e.g.:

#! /usr/bin/env bash

# Let the DB start
sleep 10;
# Run migrations
alembic upgrade head

/usr/lib/python2.7/dist-packages/supervisor/options.py:298: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
  'Supervisord is running as root and it is searching '
2018-01-05 21:25:03,606 CRIT Supervisor running as root (no user in config file)
2018-01-05 21:25:03,606 INFO Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
2018-01-05 21:25:03,613 INFO RPC interface 'supervisor' initialized
2018-01-05 21:25:03,613 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2018-01-05 21:25:03,614 INFO supervisord started with pid 7
2018-01-05 21:25:04,623 INFO spawned: 'nginx' with pid 10
2018-01-05 21:25:04,625 INFO spawned: 'uwsgi' with pid 11
[uWSGI] getting INI configuration from /app/uwsgi.ini
[uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini
*** Starting uWSGI 2.0.15 (64bit) on [Fri Jan  5 21:25:04 2018] ***
compiled with version: 6.3.0 20170516 on 10 December 2017 07:05:09
os: Linux-4.9.49-moby #1 SMP Fri Dec 8 13:40:02 UTC 2017
nodename: 5afaf51f9a4d
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /app
detected binary path: /usr/local/bin/uwsgi
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.6.3 (default, Nov  4 2017, 22:14:56)  [GCC 6.3.0 20170516]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x55e4d087cae0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 1237056 bytes (1208 KB) for 16 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x55e4d087cae0 pid: 11 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 11)
spawned uWSGI worker 1 (pid: 14, cores: 1)
spawned uWSGI worker 2 (pid: 15, cores: 1)
2018-01-05 21:25:05,843 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-01-05 21:25:05,843 INFO success: uwsgi entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

As you can see, the restart script does not seems to get executed on the linux server. The docker on both machine has been updated to the latest version.

[Question] Redirect loop

I want to redirect all www to non-www.
I have this in my custom.conf file :

server {
        server_name www.domain.com;
        return 301 $scheme://domain.com$request_uri;
}

But i receive a redirect loop. Do you have any idea why is that?
I am using the container with nginx-proxy
I think the issue happens beacuse there is double nginx-configuration.
One of nginx-proxy layer, second on uwsgi-nginx-flask-docker layer.

Isn't it better to just use pure uwsgi with nginx-proxy?

Cannot find Python module with Conda

Hi,
First of all, thanks for the great work!
I adapted the image by installing conda on top of it. I need conda to install the fast.ai library and all its dependencies. I do this on the base conda env.

When i try to run the container, it cannot find the fastai library.
However, when i run the container interactively, it runs the flask app without any issues. hence the Flask development webserver can find the fastai library but nginx/uwsgi/supervisor cannot.

Any idea how to solve this issue? What files / settings need to be adapted?

Thanks!
Francis

Connect postgres(psycopg2) with the main.py

I tried to connect postgres db from main.py, but its giving OperationalError: received invalid response to SSL negotiation: H. This issue is because the port 5432 is not properly exposed.

DOCKERFILE

FROM tiangolo/uwsgi-nginx-flask:python2.7
ENV LISTEN_PORT 5432
EXPOSE 5432
COPY tmp.conf /etc/nginx/conf.d/tmp.conf
COPY ./app /app
RUN pip install -r /app/requirements.txt

main.py

from flask import Flask
import psycopg2
app = Flask(__name__)

@app.route("/")
def hello():
    db = psycopg2.connect(host='127.0.0.1', port=5432, user='postgres',
                          password='123', dbname='chatbotdev')
    return "Hello World from Flask"

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80)

tmp.conf

server {
    listen 8080 default_server;
    listen [::]:8080 default_server;

    location / {
      try_files $uri @app;
    }

    location @app {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/uwsgi.sock;
    }
}

requirements.txt
psycopg2==2.7.3.1

Can someone please explain, how can I use postgres within this docker container, because I'm able to do this in other linux docker containers.

Cannot update server block in nginx.conf

Due to the way that the external nginx configs are included into the root nginx.conf file, it's not possible to change the primary server block, which is something I need.

As a work around, we manually update the file to include various lines, but this isn't clean and it would be nicer to just put nginx configs into a folder somewhere and have them included automatically.

ssl integration

I'm looking for a way to smoothly integrate ssl certificates through nginx config.
Any clues will be appreciated.

Connection aborted when accessing a HTTPS source

Hi,

using this image allowed me to properly start my app. However it kept failing at a certain point. I figured out that there is a problem at accessing an HTTPS source.

I isolated the respective part of my app and started it in a container. I basically just downloads a file from an S3 resource when I get the following error:

botocore.vendored.requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

However starting the flask app locally with cmd on my Windows it works perfectly fine. I also tried it on a regular Apache2 server and got the same issue so I think it has to do something with uwsgi or the reverse proxy. In the flask code below you can see that I use a custom endpoint for S3 and not the service on AWS and this server is served with SSL. Could that be an issue? Can I solve this problem by changing the configuration on this image? Thank you very much.

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def index():
    conn = boto3.client('s3', region_name="eu-west-1", endpoint_url="https://endpoint", aws_access_key_id=accesskey, aws_secret_access_key=secretkey)
    conn.download_file('mytestbucket22', 'aggregated.csv', 'aggregated.csv')
    return 'ok'

if __name__ == '__main__':
	app.run(host='0.0.0.0', debug=True)

Is not exiting gracefully

Using compose, after docker-compose up.
I ask it to quit,ctrl+C when started without detaching,
or else docker-compose down.
I noticed, that my flask-docker instance always time outs after the 10 seconds.

I believe that could be some issue with the pid-1-zombie-process thing.

Some references:

Can that issue apply here?

cannot use custom uwsgi.ini in flask app

Hi tiangolo!

I've been working around with your docker image to deploy my python application.
Things were fine until I tried customizing uwsgi.ini file.

First of all, following is my flask project architecture.

screen shot 2018-02-07 at 4 45 49 pm

Inside my Dockerfile includes following lines.

FROM tiangolo/uwsgi-nginx-flask:python3.6
COPY ./app /app
COPY ./app/conf/nginx.conf /etc/nginx/
COPY ./uwsgi.ini /app/uwsgi.ini
COPY ./requirements.txt /app/
RUN pip install -r /app/requirements.txt
ENV UWSGI_INI /app/uwsgi.ini

and I also tried with following Dockerfile.

FROM tiangolo/uwsgi-nginx-flask:python3.6
COPY ./app /app
COPY ./app/conf/nginx.conf /etc/nginx/
COPY ./uwsgi.ini /app/uwsgi.ini
COPY ./requirements.txt /app/
RUN pip install -r /app/requirements.txt
ENV UWSGI_INI /app/uwsgi.ini
WORKDIR /app

My custom uwsgi.ini is as follows.

[uwsgi]
module = main
callable = app
lazy-apps = true
processes = 1

If I run a docker container with above image, I see following logs.

screen shot 2018-02-07 at 4 57 35 pm

Thanks in advance!

How to get the container's logs?

Hi tiangolo

Great thanks for your dockers, I could setup a simple web app with flask.
I found when the app kept running somethings, it will hang up.
When I connect the running container's bash, I could only get the flask logs on the bash.
But could not get the nginx logging.

Do you have any advice for it?
Thank you

running more than 2 processes

Hi,

Thanks for the great work. I've tried specifying the number of processes in uwsgi.ini, however it still defaults to 2. How do I spawn more than 2 processes?

Thanks.

Using root as user

Why do you not change user? Is it secure to run uWSGI with root privileges?

cant connect mongodb

why can,t connect mongodb
eg:
data=source_client.users.users.find({"_id":ObjectId('5840e3eaf1d30043c60cae53')})[0]

feedback:

<title>500 Internal Server Error</title>

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

How could I fixed the dockerfile setting?

Yesterday, I build a new dockerfile with my python project as usual. But when I start it up, the static files all broken down.

After some time debugging I found the static file path is not config as usual.

I use the COPY in dockerfile building to change the nginx static file path.
But now it did not working.
I try some other ways, it was still not working too.

Suddenly, I realize that maybe there is some thing wrong in the entrypoint.sh

Aha, you have change the static file config to ENV in docker file.

So I fix it following the instruction.

But I am worry about that if it will change some way sometimes in the future.

So my question is how could I get a fixed dockerfile settings but not auto update with the repository?

Thank you.

Too many “SIGPIPE: writing to a closed pipe/socket/fd” error for every seconds, on Flask + Nginx

Currently, I have the following simple Flask + Nginx web application.

Dockerfile

FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7


# Install the required packages
RUN pip install celery


COPY . /app

main.py

import json
import os
from flask import Flask, request
from flask import url_for
from celery import Celery
from celery.result import AsyncResult
import celery.states as states
import constants
import logging


app = Flask(__name__)


@app.route('/stock_price_alert', methods = ['POST'])
def stock_price_alert():
    request_data = request.get_json()

    if not request_data:
        return 'empty_data'

    celery = Celery('stock_price_alert', broker=constants.CELERY_BROKER_URL, backend=constants.CELERY_RESULT_BACKEND)
    celery.send_task('stock_price_alert.run', queue='stock_price_alert', args=[request_data], kwargs={})
    return 'stock_price_alert'


if __name__ == '__main__':
    app.run(debug=env.get('DEBUG',True),
            port=int(env.get('PORT',5000)),
            host=env.get('HOST','0.0.0.0')
    )

I have another node.js app, which will perform POST to /stock_price_alert, like every 10 seconds.

function post_stock_price_to_flask(json) {
    var options = {
      uri: 'http://flask/stock_price_alert',
      method: 'POST',
      json: json
    };
    
    request(options, function (error, response, body) {
    });

Things work pretty OK for few hours, till my CPU suddenly spike up.

enter image description here

Then, I keep receiving the error log, if I perform docker-compose logs flask

flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:55 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!
flask_1                            | Mon Feb 26 19:44:56 2018 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /stock_price_alert (ip 172.18.0.8) !!!

I even shutdown the node.js app, to ensure no one is sending POST to /stock_price_alert

Still, after I shutdown my node.js, Flask still keep generating the error log, and the CPU usage still very high.

May I know is there any other thing I can debug?

p/s Here's my docker stats output

CONTAINER ID        NAME                                                   CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
357b5cd5c472        jstocknotification_flask_1                             56.18%              127.7MiB / 992.3MiB   12.87%              267MB / 220MB       94.7GB / 4.1kB      8

Cannot load submodule

I have a project with structure below:

- /
  |- src
    |- main.py
    |- __init__.py
    |- submodule
      |- __init__.py
      |- ... 
    |- web
      |- web.py
      |- __init__.py
  |- Dockerfile

main.py calls entry function defined in web.py, and web.py calls functions defined in submodule. It works fine with command line python main.py. Then I plan to deploy it under docker, with Dockerfile:

FROM tiangolo/uwsgi-nginx-flask:python3.6
COPY ./src/* /app/

Build and run, I got error:

Traceback (most recent call last):
  File "./main.py", line 1, in <module>
    from web import run
  File "./web.py", line 5, in <module>
    import submodule
ModuleNotFoundError: No module named 'submodule'

Why did uwsgi cannot find submodule? Did I miss something?

Include libmysqlclient-dev

Many / most applications need a database. Can you add these dependencies, or show how you would recommend we add them ourselves?

Default uwsgi.ini overrides settings in the custom configuration

Hi, first of all, thank you for your great work!

I found a problem while deploying my app, which has a custom uwsgi.ini inside the app folder, on top of this docker image.
I want to set a different value for cheaper, but while changing all other cheaper-related settings (cheaper-initial, cheaper-step) works, settings cheaper=5 doesn't because the default uwsgi.ini (/etc/uwsgi/uwsgi.ini) sets cheaper = 2.

I validated this issue by overriding /etc/uwsgi/uwsgi.ini with my custom settings.
I guess the same will happen by trying to set processes (which is also declared in the deault uwsgi.ini) to a value different from 16.

I would be happy to create a PR fixing this issue, but I need some guidance on the way it merges the 2 configs (default and the custom one in /app) 🙂

Some problems with from my Module import

2018-02-12 19:41:49:--- no python application found, check your startup logs for errors ---
2018-02-12 19:41:49:[pid: 11|app: -1|req: -1/8] 192.168.1.169 () {42 vars in 658 bytes} [Mon Feb 12 11:28:47 2018] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
2018-02-12 19:41:49:192.168.1.169 - - [12/Feb/2018:11:28:47 +0000] "GET / HTTP/1.1" 500 32 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0" "-"
2018-02-12 19:41:49:Checking for script in /app/prestart.sh
2018-02-12 19:41:49:Running script /app/prestart.sh
2018-02-12 19:41:49:Running inside /app/prestart.sh, you could add migrations to this file, e.g.:
2018-02-12 19:41:49:#! /usr/bin/env bash
2018-02-12 19:41:49:# Let the DB start
2018-02-12 19:41:49:sleep 10;
2018-02-12 19:41:49:# Run migrations
2018-02-12 19:41:49:alembic upgrade head
2018-02-12 19:41:49:/usr/lib/python2.7/site-packages/supervisor/options.py:298: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
2018-02-12 19:41:49:  'Supervisord is running as root and it is searching '
2018-02-12 19:41:49:2018-02-12 11:39:54,856 CRIT Supervisor running as root (no user in config file)
2018-02-12 19:41:49:2018-02-12 11:39:54,858 INFO Included extra file "/etc/supervisor.d/supervisord.ini" during parsing
2018-02-12 19:41:49:Unlinking stale socket /run/supervisord.sock
2018-02-12 19:41:49:2018-02-12 11:39:55,215 INFO RPC interface 'supervisor' initialized
2018-02-12 19:41:49:2018-02-12 11:39:55,217 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2018-02-12 19:41:49:2018-02-12 11:39:55,219 INFO supervisord started with pid 5
2018-02-12 19:41:49:2018-02-12 11:39:56,231 INFO spawned: 'nginx' with pid 8
2018-02-12 19:41:49:2018-02-12 11:39:56,244 INFO spawned: 'uwsgi' with pid 9
2018-02-12 19:41:49:[uWSGI] getting INI configuration from /app/uwsgi.ini
2018-02-12 19:41:49:[uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini
2018-02-12 19:41:49:*** Starting uWSGI 2.0.15 (64bit) on [Mon Feb 12 11:39:56 2018] ***
2018-02-12 19:41:49:compiled with version: 6.4.0 on 10 November 2017 03:49:42
2018-02-12 19:41:49:os: Linux-4.13.9-300.fc27.x86_64 #1 SMP Mon Oct 23 13:41:58 UTC 2017
2018-02-12 19:41:49:nodename: 9139e94a8606
2018-02-12 19:41:49:machine: x86_64
2018-02-12 19:41:49:clock source: unix
2018-02-12 19:41:49:pcre jit disabled
2018-02-12 19:41:49:detected number of CPU cores: 1
2018-02-12 19:41:49:current working directory: /app
2018-02-12 19:41:49:detected binary path: /usr/sbin/uwsgi
2018-02-12 19:41:49:your processes number limit is 1048576
2018-02-12 19:41:49:your memory page size is 4096 bytes
2018-02-12 19:41:49:detected max file descriptor number: 1048576
2018-02-12 19:41:49:lock engine: pthread robust mutexes
2018-02-12 19:41:49:thunder lock: disabled (you can enable it with --thunder-lock)
2018-02-12 19:41:49:uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
2018-02-12 19:41:49:uWSGI running as root, you can use --uid/--gid/--chroot options
2018-02-12 19:41:49:*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
2018-02-12 19:41:49:Python version: 3.6.3 (default, Nov 21 2017, 14:55:19)  [GCC 6.4.0]
2018-02-12 19:41:49:*** Python threads support is disabled. You can enable it with --enable-threads ***
2018-02-12 19:41:49:Python main interpreter initialized at 0x55a0a775f4c0
2018-02-12 19:41:49:your server socket listen backlog is limited to 100 connections
2018-02-12 19:41:50:your mercy for graceful operations on workers is 60 seconds
2018-02-12 19:41:50:mapped 1237056 bytes (1208 KB) for 16 cores
2018-02-12 19:41:50:*** Operational MODE: preforking ***
2018-02-12 19:41:50:2018-02-12 11:39:57,489 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-02-12 19:41:50:2018-02-12 11:39:57,491 INFO success: uwsgi entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-02-12 19:41:50:Traceback (most recent call last):
2018-02-12 19:41:50:  File "./app/main.py", line 12, in <module>
2018-02-12 19:41:50:    from DBconfig import DB, Carriage, Carriage_plan, Train_plan
2018-02-12 19:41:50:ModuleNotFoundError: No module named 'DBconfig'
2018-02-12 19:41:50:unable to load app 0 (mountpoint='') (callable not found or import error)
2018-02-12 19:41:50:*** no app loaded. going in full dynamic mode ***
2018-02-12 19:41:50:*** uWSGI is running in multiple interpreter mode ***
2018-02-12 19:41:50:spawned uWSGI master process (pid: 9)
2018-02-12 19:41:50:spawned uWSGI worker 1 (pid: 11, cores: 1)
2018-02-12 19:41:50:spawned uWSGI worker 2 (pid: 12, cores: 1)
2018-02-12 19:42:13:--- no python application found, check your startup logs for errors ---
2018-02-12 19:42:13:[pid: 11|app: -1|req: -1/1] 192.168.1.169 () {42 vars in 658 bytes} [Mon Feb 12 11:42:13 2018] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (1 switches on core 0)
2018-02-12 19:42:13:192.168.1.169 - - [12/Feb/2018:11:42:13 +0000] "GET / HTTP/1.1" 500 32 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0" "-"

i see the problem is from DBconfig import DB, Carriage, Carriage_plan, Train_plan。
but the DBconfig is my file . set some thing about SQLAlchemy

directory structure like:


.
├── app
│   ├── app
│   │   ├── alembic.ini
│   │   ├── build requirement.py
│   │   ├── DBconfig.py
│   │   ├── ghostdriver.log
│   │   ├── main.py
│   │   ├── migrate
│   │   │   ├── env.py
│   │   │   ├── __pycache__
│   │   │   │   └── env.cpython-36.pyc
│   │   │   ├── README
│   │   │   └── script.py.mako
│   │   ├── Plan.db
│   │   ├── requirements.txt
│   │   ├── static
│   │   │   ├── css
│   │   │   │   ├── bootstrap.css
│   │   │   ├── DatePicker
│   │   │   │   ├── css
│   │   │   │   │   ├── bootstrap-datepicker3.css
│   │   │   │   ├── js
│   │   │   │   │   ├── bootstrap-datepicker.js
│   │   │   │   └── locales
│   │   │   │       ├── bootstrap-datepicker.ar.min.js
│   │   │   │       └── bootstrap-datepicker.zh-TW.min.js
│   │   │   ├── favicon.ico
│   │   │   ├── js
│   │   │   │   ├── bootstrap.bundle.js
│   │   │   ├── test.png
│   │   │   └── timg.jpg
│   │   ├── templates
│   │   │   ├── base.html
│   │   │   ├── carriage.html
│   │   │   ├── plan.html
│   │   │   └── Untitled-1.htm
│   │   ├── test.py
│   │   ├── TODO.txt
│   │   └── tools
│   │       ├── cc.json
│   │       ├── geckodriver.log
│   │       ├── ghostdriver.log
│   │       ├── phantomjs.exe
│   │       ├── __pycache__
│   │       │   ├── spider.cpython-36.pyc
│   │       │   └── xpath.cpython-36.pyc
│   │       ├── read_plan.py
│   │       ├── spider.py
│   │       └── xpath.py
│   └── uwsgi.ini
└── Dockerfile

Dockerfile

FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7

COPY ./app /app
RUN  pip install -r /app/app/requirements.txt

requirements.txt:

click==6.7
Flask==0.12.2
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
selenium==3.9.0
SQLAlchemy==1.2.2
Werkzeug==0.14.1
xlrd==1.1.0

sorry for my bad english。
I think you can understand the problem。

now i try this:
#from DBconfig import DB, Carriage, Carriage_plan, Train_plan
it work out mydatabase.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.