Comments (7)
@aleonchen all the logs are redirected to stdout
. It means, that you don't need to connect with bash, they are readable with:
docker logs <your container>
- If you only want, let's say, the last 50 lines:
docker logs --tail=50 <your container>
- If you want it to keep showing the log "live" (without having to re-type the previous commands) you can:
docker logs -f <your container>
from uwsgi-nginx-flask-docker.
@tiangolo
Great thanks. I have tried this.
But it could only show the flask logging info.
How could I get the nginx logging?
For example the access.log or error.log
from uwsgi-nginx-flask-docker.
The thing is, you should be already getting those logs.
For example, if you try requesting something inside /static/
, let's say /static/index.html
. You should get something in your log like:
10.42.144.135 - - [26/Apr/2017:17:26:50 +0000] "GET /static/index.html HTTP/1.1" 200 7429 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36" "186.154.85.228"
That log would be from Nginx. As Flask doesn't even get the request. Nginx reads it and sees that you are asking for something under /static/
, and then it just goes away and serves it, without asking anything from the Python side.
But if you are running any CMD
in your image, you are overriding all the "magic" done by this image. The same if you are passing a specific command to your docker run
, as in:
docker run -it myimage python /app/main.py
That is useful for developing and / or debugging, but for "production", or when you want to test the Supervisord / Nginx / uWSGI functionality that this image provides, you should remove those CMD
or direct commands.
from uwsgi-nginx-flask-docker.
OK, I got what you say, but I found that when I run the docker for some time. The flask web service will hung up, and I could not found what the issue is.
For example
Step 1
I start up the docker as production.
docker run --rm -d -v $(pwd)/webapp:/app -p 80:5000 --link mysql:mysql --name containername imagename
Step 2
After sometime no response with the request.
I use the docker logs -f containername
to see the logs
It is always stop on some logs like
xx.xx.xx.xx - - [27/Apr/2017 18:22:15] "GET / HTTP/1.1" 302
Step 3
I want to check if where is wrong, the nginx or python, but I have no idea about it.
from uwsgi-nginx-flask-docker.
Well, the first thing, the trick of the $(pwd)/webapp:/app
should be used in development, not in production.
If Nginx was not being able to communicate with uWSGI (Flask) it would report it, with something saying that it couldn't connect to the socket or something similar.
I can't help you debug it if you only post the idea you have of the log. You need to copy the real log for me to be able to try to help you. When you get the error, copy a big chunk of the log. With what you have provided I can't really check anything.
Also, let me suggest you to use Sentry. You can create a free account or deploy yourself the opensource version with Docker. That will help you a lot detecting problems in your code.
from uwsgi-nginx-flask-docker.
@tiangolo After some digging I found the problem.
When I use docker exec -it <container> ps aux
The uwsgi and nginx is not running.
Then I check the Dockerfile and found the issue.
FROM tiangolo/uwsgi-nginx-flask:flask-python3.5
MAINTAINER aleonchen "[email protected]"
COPY ./webapp/requirements.txt /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["main.py"]
I shoud remove the last two lines.
Thanks a lot for your patient.
But now my question is if I do not use $(pwd)/webapp:/app
, what is the good way to update the code on server side?
Every time update the code rebuild the image?
from uwsgi-nginx-flask-docker.
I'm glad you were able to solve your issue!
The best way is to COPY ./webapp/ /app/
in your Dockerfile. And when you have a newer version, re-build the image and replace the old container.
Your "state" shouldn't be in that container anyway, it should be in a database in another container. Or at least, in a volume, like a named volume.
Then, I will now close this issue.
from uwsgi-nginx-flask-docker.
Related Issues (20)
- Nginx arm64 HOT 2
- SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC HOT 1
- Need nginx 1.21.3
- Is it possible to suppress all `chown` calls?
- Application Factory guidance
- Ubuntu 18 or ubuntu 20.04 for uwsgi-nginx-flask-docker
- Iām getting an SSL error. HOT 1
- How to upgrade nginx through dockerfile
- Set PYTHONDONTWRITEBYTECODE environment variable
- Set PYTHONUNBUFFERED env variable
- Why running flask app.run with gunicorn and uwsgi is problematic?
- Consistent 502 Bad Gateway HOT 1
- ARM64 support HOT 3
- How to run HTTPS using waitress?
- configuring for image uploads and ML inference - issues with file buffering HOT 1
- server location
- All static files return 403 HOT 1
- Support for arm64
- How to obtain the real user IP address.
- Running Dockerfile on ARM architecture HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uwsgi-nginx-flask-docker.