Code Monkey home page Code Monkey logo

Comments (7)

tiangolo avatar tiangolo commented on May 22, 2024

@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.

aleonchen avatar aleonchen commented on May 22, 2024

@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.

tiangolo avatar tiangolo commented on May 22, 2024

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.

aleonchen avatar aleonchen commented on May 22, 2024

@tiangolo

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.

tiangolo avatar tiangolo commented on May 22, 2024

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.

aleonchen avatar aleonchen commented on May 22, 2024

@tiangolo After some digging I found the problem.

When I use docker exec -it <container> ps aux
The uwsgi and nginx is not running.

2017-04-29 9 27 14

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.

tiangolo avatar tiangolo commented on May 22, 2024

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)

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.